CSS Fonts & Text Styling Explained: Short & Clear Guide with Examples, Tips & Related Posts
Master CSS font and text formatting fast with short, clear visual examples covering font-family, font-weight, line-height, text-align, web fonts, text-shadow, typography tips, and related posts opening in a new tab.
2026-10-02 ยท 6 min read
Typography is the backbone of web design. Over 90% of information on the web is written text. Mastering CSS font and text properties allows you to create readable, accessible, and visually stunning user interfaces.
Here is a short, clear, and visual guide to CSS fonts and text styling. ๐
๐ก Core Concept: Font Properties vs. Text Properties
In CSS, typography rules fall into two distinct groups:
- Font Properties: Define the typeface itself (family, size, weight, style).
- Text Properties: Control how the text is aligned, spaced, transformed, and decorated inside its container.
โก Quick Cheatsheet
| Category | Property | Common Values | What It Controls |
|---|---|---|---|
| Font | font-family | Inter, sans-serif | system-ui | Typeface family choice |
font-size | 16px | 1rem | clamp(1rem, 2.5vw, 2rem) | Text size | |
font-weight | 400 (normal) | 600 (semibold) | 700 (bold) | Text thickness | |
font-style | normal | italic | Normal vs slanted italic text | |
| Text | color | #1e293b | rgb(59 130 246) | Text color |
text-align | left | center | right | justify | Horizontal text alignment | |
line-height | 1.5 | 1.6 | 1.2 | Spacing between text lines | |
letter-spacing | 0.5px | -0.02em | Horizontal letter spacing | |
text-transform | uppercase | lowercase | capitalize | Text capitalization | |
text-decoration | none | underline | line-through | Text underline / strike-through | |
text-shadow | 2px 2px 4px rgba(0,0,0,0.3) | Text drop shadow |
๐ฆ Essential Code Examples
1. Modern System Font Stack
Using system font stacks gives your application native OS speeds with zero layout shift (CLS) and zero web font downloads.
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
font-size: 1rem; /* 16px base size */
line-height: 1.6; /* Optimal line spacing for body text */
color: #0f172a; /* Dark slate text */
}
2. Importing & Using Google Web Fonts
Import custom Google Fonts (like Inter or Roboto) directly in CSS or HTML <head>.
/* Import Google Font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
.heading {
font-family: 'Inter', sans-serif;
font-weight: 700;
font-size: 2.25rem;
letter-spacing: -0.025em; /* Subtle tight tracking for headings */
}
3. Text Alignment & Line Spacing
Controls text layout, line spacing, and letter spacing for optimal readability.
.article-text {
text-align: left;
line-height: 1.7; /* Comfortable reading height */
letter-spacing: 0.2px; /* Added breathing room */
}
โก Live Result Preview:
Good typography makes reading effortless. When line-height is set too low, multi-line text becomes tight, difficult to read, and strains the user's eyes.
Good typography makes reading effortless. When line-height is set to 1.5 or 1.6, text has comfortable breathing room between lines!
4. Text Truncation with Ellipsis (...)
Truncate long text seamlessly to fit single-line or multi-line cards.
/* Single-line Truncation */
.truncate-single {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/* Multi-line Truncation (2 Lines) */
.truncate-multi {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
โก Live Result Preview:
5. Text Transformation, Decoration & Shadow
Styling buttons, badge headers, and glowing text.
.badge {
text-transform: uppercase; /* UPPERCASE text */
font-weight: 700;
letter-spacing: 1px;
}
.glowing-text {
color: #ffffff;
text-shadow: 0 0 10px rgba(59, 130, 246, 0.8), 0 0 20px rgba(59, 130, 246, 0.4);
}
๐ฏ 5 Essential Typography Pro Tips
Tip 1: Always Use Unitless line-height
Never use px or em units for line-height. Use unitless values like 1.5 or 1.6. Unitless values multiply relative to the element's actual font size, preventing child text overlap bugs!
Tip 2: Limit Content Width to 65 Characters (65ch)
For maximum reading comfort on articles and blogs, set max-width: 65ch; on paragraph containers. Lines that are too long cause reader eye fatigue.
.article-body {
max-width: 65ch; /* ~65 characters per line */
margin-inline: auto;
}
Tip 3: Enable Smooth Web Font Antialiasing
Add webkit font smoothing for crisp text rendering on macOS, iOS, and modern screens:
body {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
Tip 4: Responsive Fluid Typography with clamp()
Scale font sizes smoothly from mobile to desktop screens without writing media queries!
h1 {
/* clamp(MIN, VAL, MAX) */
font-size: clamp(1.75rem, 4vw, 3rem);
}
Tip 5: Use font-display: swap for Web Fonts
When loading custom Google or Adobe web fonts, add font-display: swap; to prevent invisible text while the font is downloading (FOIT).
๐ Related Posts & Useful Resources
Explore these official typography guides, free font libraries, and related CSS tutorials. All external and internal reference links open in a new tab.
๐ Official Typography Specs & Web Font Libraries (New Tab)
- Google Fonts โ Free Open Source Web Fonts Library
- MDN Web Docs โ Fundamental Text and Font Styling Guide
- Web.dev โ Learn Typography Basics & Web Fonts
๐ท๏ธ Related CSS Tutorials on dev.rean.me (New Tab)
- How to Use Khmer & English Fonts in CSS (With Tutorial)
- CSS Media Queries Explained: Short & Clear Guide with Examples
- CSS Flexbox Explained: Short & Clear Guide with Examples & Pro Tips
- CSS Grid Explained: Short & Clear Guide with Examples & Pro Tips
- CSS Positioning Explained: Static, Relative, Absolute, Fixed & Sticky
- CSS Cheat Sheet: Essential Syntax, Box Model & Properties
- CSS Tips and Tricks with Practical Code Examples
- Complete CSS Property & Selector Reference Guide
Happy typography designing! If you found this short & clear CSS Fonts & Text Style guide helpful, feel free to share it with fellow developers! ๐จโก