px
Direct pixel sizing. Predictable, but less flexible as a system.
Font size controls hierarchy, scanning and reading comfort. Good font-size decisions create order before users read a single paragraph.
h1 {
font-size: clamp(2.5rem, 7vw, 5rem);
}
Typography & Visual Style
Font size tells users what matters first. A headline, label, button and paragraph should not all compete at the same size.
CSS supports absolute and relative units. Pixels are direct, rem is based on the root font size, em is based on the current element context, and clamp() creates fluid responsive sizing.
A strong website uses a type scale instead of random font sizes. That creates rhythm, consistency and easier maintenance.
Direct pixel sizing. Predictable, but less flexible as a system.
Relative to the root font size. Excellent for scalable typography.
Relative to the current font size. Useful but can compound.
A fluid value with a minimum, preferred value and maximum.
Visual model
Typography and visual style are where CSS starts to feel like design. These models turn subjective choices into reusable decisions you can explain, test and improve.
Metadata, captions and subtle labels.
Body text and ordinary interface text.
Section headings or important labels.
Responsive display text.
Examples
:root {
--text-base: 1rem;
--text-title: clamp(2.5rem, 7vw, 5rem);
}
h1 { font-size: var(--text-title); }
h1 { font-size: 73px; }
h2 { font-size: 41px; }
.card-title { font-size: 27px; }
.small { font-size: 11.5px; }
Rules that matter
A beautiful one-off style is not enough. The goal is a visual system that keeps working when the site grows, content changes and new pages are added.
A scale makes typography feel intentional across pages.
rem values respond well to root size and user settings.
Hero text can adapt without many breakpoints.
Body text that is too small makes learning harder.
Viewport-only sizing can become extreme on wide screens.
A dashboard panel heading should not look like a landing page hero.
Production thinking
Font size is the fastest way to build hierarchy. Without it, users have to work harder to understand the page.
Relative units and readable base sizes support zoom, user preferences and long reading sessions.
Define type tokens early. Random font sizes multiply quickly in a large site.
Clear hierarchy helps users scan content, which supports engagement and comprehension.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If your answer is vague, change the lab values and judge the visual result again.
Senior audit upgrade
Font-size decisions should survive browser zoom and user preferences. rem-based systems usually scale more predictably than fixed pixel thinking.
Use rem for system-level type sizes that should follow the root font size.
Use em when a value should relate to the current element font size.
Check the page at 200 percent zoom before calling a type scale production-ready.