body {
font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}
code, pre {
font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
}
Note Always end the stack with a generic family (sans-serif, serif, monospace, cursive, system-ui). The system-ui keyword uses the operating system's default font. Quotes are required when font names contain spaces.
font familychange fontfont stacksystem fontmonospace font
Font Size
syntax
font-size: value; /* px, rem, em, %, clamp() */
example
html {
font-size: 16px; /* base for rem units */
}
body {
font-size: 1rem;
}
h1 {
font-size: clamp(1.75rem, 4vw, 3rem);
}
.small-text {
font-size: 0.875rem; /* 14px at 16px base */
}
Note Use rem for consistent sizing relative to the root. em is relative to the parent's font size which compounds in nested elements. clamp() creates fluid typography that scales between a minimum and maximum.
font sizetext sizerem vs emfluid typographyresponsive font
Font Weight
syntax
font-weight: 100-900 | normal | bold | lighter | bolder;
Note 100=Thin, 200=ExtraLight, 300=Light, 400=Normal, 500=Medium, 600=SemiBold, 700=Bold, 800=ExtraBold, 900=Black. The font file must include the requested weight or the browser will fake bold, which looks poor.
Note Use unitless numbers (like 1.6) rather than fixed units so the line height scales proportionally with font size. Body text typically reads best between 1.5 and 1.7. Headings look better tighter at 1.1 to 1.3.
line heightline spacingtext spacingleading
Text Align
syntax
text-align: left | center | right | justify | start | end;
Note Prefer start and end over left and right for internationalization support (RTL languages). Avoid text-align: justify for body text on the web since it creates uneven word spacing without hyphenation.
text aligncenter textright aligntext alignmentjustify text
Text Decoration
syntax
text-decoration: line style color thickness;
text-underline-offset: value;
Note Use text-underline-offset to move underlines away from the text baseline for better readability. text-decoration-skip-ink: auto (the default in most browsers) makes underlines skip descenders cleanly.
Note When using uppercase, add letter-spacing (0.04em to 0.1em) to improve readability. Keep actual content in normal case in the HTML since text-transform is purely visual and screen readers may spell out uppercase letters.
Note Use em units for letter-spacing so it scales with font size. Tight letter-spacing works well for large headings. Wide letter-spacing suits small uppercase labels.
letter spacingword spacingtrackingcharacter spacing
Word Break & Overflow Wrap
syntax
word-break: normal | break-all | keep-all;
overflow-wrap: normal | break-word | anywhere;
Note overflow-wrap: break-word only breaks long words that would overflow their container. word-break: break-all breaks between any characters, even mid-word. Use overflow-wrap for most cases and word-break: break-all only for data like hashes or URLs.
word breakbreak wordlong texttext overflowwrap text
Note text-wrap: balance distributes text evenly across lines, preventing headings with one orphaned word on the last line. text-wrap: pretty focuses on avoiding orphans in body text. balance has a limit of a few lines for performance reasons.
text wrap balanceeven text linesavoid orphansbalanced headingpretty text
Note Use font-display: swap to show fallback text while the font loads, preventing invisible text. WOFF2 offers the best compression. Preload critical fonts with <link rel="preload" as="font" crossorigin>.
web fontcustom fontfont faceload fontwoff2font display