π Introduction
The font-weight property in CSS controls how bold or light your text appears. It's essential for creating hierarchy, emphasis, and a professional visual design. Proper usage improves readability and helps users quickly scan your content. β¨
π What is font-weight?
The font-weight property specifies the thickness of characters. It can accept keyword values like normal, bold, or numeric values from 100β900.
Basic Usage
p {
font-weight: bold;
}π’ Numeric Font Weights (100β900)
Many fonts support a range of numeric weight values. Lower numbers = lighter text, Higher numbers = bolder text.
| Value | Weight | Example Usage |
|---|---|---|
| 100 | Thin | Subtle headings |
| 200 | Extra Light | Minimal UI |
| 300 | Light | Body text (light themes) |
| 400 | Normal | Standard paragraphs |
| 500 | Medium | UI labels |
| 600 | Semi Bold | Subheadings |
| 700 | Bold | Headings |
| 800 | Extra Bold | Strong emphasis |
| 900 | Black | Maximum impact |
Note
π§ Keyword Values
- πΉ normal β Equivalent to
400 - πΉ bold β Equivalent to
700 - πΉ lighter β One level lighter than the parent
- πΉ bolder β One level bolder than the parent
Keyword Example
h1 {
font-weight: bold;
}
p {
font-weight: lighter;
}π― Example: Using Numeric Weights
Numeric Weights
h1 {
font-weight: 700;
}
h2 {
font-weight: 600;
}
p {
font-weight: 400;
}
small {
font-weight: 300;
}π₯ Using Variable Fonts
Modern variable fonts allow smooth transitions between weights, not just fixed values. This provides more control and better performance.
Variable Font Example
@font-face {
font-family: "Inter";
src: url("Inter-VariableFont.woff2") format("woff2-variations");
font-weight: 100 900;
}
p {
font-weight: 450; /* Works with variable fonts */
}Note
πΈ Visual Demo
Further details can be found at: https://dummyimage.com/800x260/ddd/000&text=font-weight+100+to+900
π Real-World Example
Hereβs how weights are typically used in UI design:
UI Typography Example
.title {
font-weight: 700;
}
.subtitle {
font-weight: 500;
}
.body {
font-weight: 400;
}
.caption {
font-weight: 300;
}π‘ Best Practices
- βοΈ Use 400 for normal text.
- βοΈ Use 500β600 for subheadings.
- βοΈ Use 700+ for main headings to create hierarchy.
- βοΈ Avoid extremely heavy weights for long text.
- βοΈ Check the font's supported weights before using numeric values.
π Conclusion
The font-weight property is a powerful way to control how bold or light your text appears. By understanding keyword values, numeric weights, and variable fonts, you can create better visual structure and improve readability in your designs. π