Lesson 16: Mastering Font Weight and Style
Learn how to control text emphasis with font-weight and font-style properties. Understand bold, italic, and oblique text, and how to use them effectively in your designs.
Start LearningUnderstanding Font Weight and Style
Font weight and style are essential for creating visual hierarchy and emphasis in your typography. They help guide readers' attention and convey meaning beyond the text itself.
Font Weight Examples
Font Style Examples
CSS Font Weight and Style Syntax
/* Basic font weight */ .heading { font-weight: bold; /* or 700 */ } .subheading { font-weight: 600; } .paragraph { font-weight: normal; /* or 400 */ } .light-text { font-weight: 300; } /* Font styles */ .emphasis { font-style: italic; } .code { font-style: oblique; } /* Removing default styles */ em { font-style: normal; } /* Combining with other properties */ .callout { font-weight: 700; font-style: italic; color: var(--primary); }
Advanced Properties and Values
Modern CSS provides more control over font weight and style, including variable fonts and precise angle control for oblique text.
Variable Fonts
Variable fonts allow continuous variation in weight, width, and other attributes. This provides greater flexibility and reduces the number of font files needed.
@font-face { font-family: 'InterVariable'; src: url('Inter.var.woff2') format('woff2-variations'); font-weight: 100 900; } .variable-text { font-family: 'InterVariable', sans-serif; font-variation-settings: 'wght' 375; }
Oblique Angle
With modern CSS, you can specify the exact angle of oblique text. This provides more control over the slant of your text.
.custom-oblique { font-style: oblique 15deg; } /* Fallback for older browsers */ @supports not (font-style: oblique 15deg) { .custom-oblique { font-style: italic; transform: skewX(-15deg); display: inline-block; } }
Responsive Typography with Font Weight
/* Base styles */ h1 { font-weight: 700; } /* Adjust weight for smaller screens */ @media (max-width: 768px) { h1 { font-weight: 600; /* Slightly lighter on mobile */ } h2 { font-weight: 500; } } /* Using clamp for fluid typography */ .hero-heading { font-weight: clamp(600, 8vw, 800); font-size: clamp(2rem, 5vw, 3.5rem); }
Interactive Font Demo
Experiment with different font weight and style options and see the results in real-time:
.preview { font-weight: 400; font-style: normal; }
Real-World Use Cases
Heading Hierarchy
Main Heading (800)
Subheading (700)
Section Heading (600)
Use varying font weights to establish a clear visual hierarchy for headings.
Emphasis in Text
This is a bold word, this is an italic word, and this is a bold italic word.
Combine font weight and style to create different levels of emphasis in your content.
Code Samples
function calculateTotal(price, tax) {
return price * (1 + tax);
}
Use oblique style for code samples to differentiate them from regular text.
Best Practices
Follow these guidelines for effective use of font weight and style:
<strong>
and <em>
tags for semantic meaning before applying visual styles.
Font Weight vs. Style Usage
Creative Typography Techniques
/* Dynamic heading with variable weight */ h1 { font-weight: clamp(600, 8vw, 800); } /* Italic first paragraph */ article > p:first-of-type { font-style: italic; font-weight: 450; } /* Gradual weight change in hero text */ .hero-text span { display: inline-block; } .hero-text span:nth-child(1) { font-weight: 300; } .hero-text span:nth-child(2) { font-weight: 400; } .hero-text span:nth-child(3) { font-weight: 500; } .hero-text span:nth-child(4) { font-weight: 600; } .hero-text span:nth-child(5) { font-weight: 700; } /* Responsive italic adjustment */ @media (max-width: 768px) { .long-quote { font-style: normal; } }
Common Mistakes to Avoid
Be aware of these pitfalls when using font weight and style:
Overusing Bold
Making everything bold reduces its impact and makes content harder to scan.
Solution: Reserve bold for key elements like headings and important calls-to-action.
Excessive Italics
Long sections of italic text are harder to read and strain the eyes.
Solution: Limit italics to short phrases, quotes, or specialized terms.
Ignoring Font Capabilities
This light weight may not render well on all systems
Solution: Check font weight support and provide fallbacks for unsupported weights.
Next Steps
Now that you understand font weight and style, continue to the next lesson to learn about text shadows and other text effects.