CSS Font Weight

The CSS font-weight property is used to specify the thickness or boldness of text. It controls how thick or thin the characters in a text should appear. The font weight can be set to a keyword or a numeric value, with the most common use being to apply boldness to text.

Key Points on CSS Font Weight:

Font Weight Values

Syntax for CSS Font Weight:

Syntax Example

/* Font weight syntax */
        .element {
            font-weight: value;
                 }
        
        /* Example */
        p {
            font-weight: bold;
        }

Examples of CSS Font Weight:

The following examples demonstrate how to use the font-weight property with different values:

Code Example: Font Weight Normal


            p {
            font-weight: normal;
              }

Output

This paragraph has normal font weight.

Code Example: Font Weight Bold


            p {
            font-weight: bold;
              }

Output

This paragraph has bold font weight.

Code Example: Font Weight Using Numeric Value


            p {
            font-weight: 700;
              }

Output

This paragraph has a numeric font weight of 700, which is bold.

Code Example: Font Weight Bolder


            p {
            font-weight: bolder;
              }

Output

This paragraph has a bolder font weight than its parent element.

Code Example: Font Weight Lighter


            p {
            font-weight: lighter;
              }

Output

This paragraph has a lighter font weight than its parent element.

Code Example: Font Weight Using Numeric Values 100-900


            p {
            font-weight: 400; /* Normal weight */
              }

Output

This paragraph has a font weight of 400, which is normal weight.

Font Weight and Readability:

When applying font weights, consider the context and purpose of your design. Bold text should be used sparingly for emphasis, while normal weights can provide a clean, legible body text style. Experiment with different weights to achieve the desired impact without sacrificing readability.