Typography is most of what users perceive as “design.” Good HTML gives headings and paragraphs; CSS makes them comfortable to read.
Practical rules
- Body text:
line-heightaround 1.5–1.7. - Prefer
remfor font sizes so users who zoom see consistent scaling. - Limit line length (~60–75 characters) with
max-widthon text containers. - Ensure contrast: dark text on light backgrounds (check WCAG for production).
Heading hierarchy
Use one <h1> per page view, then h2, h3 without skipping levels when possible. Style sizes in CSS—not by picking the wrong heading level.
Practice
- Change
--font-size-baseand watch the whole page scale. - Set
max-widthon.proseand compare readability.
Important interview questions and answers
- Q: Why use `rem` instead of `px` for font-size?
A: `rem` respects root font size and user zoom preferences better than fixed pixels. - Q: What is a common accessible line-height for body text?
A: Around 1.5 or higher depending on font and size. - Q: Should heading level be chosen for font size?
A: No—choose level for document structure; size is CSS.