Web typography basics
Typography is how text looks and feels on a page.
Good typography makes your content easier to read. It also helps headings, paragraphs, buttons, and labels feel organized.
In CSS, typography is controlled with properties such as font-family, font-size, line-height, text-align, and simple formatting rules.
What web typography means
Web typography means choosing and styling text for a website.
It is not only about making text bigger or smaller. It also includes:
- which font is used
- how large the text is
- how much space sits between lines
- whether text is aligned left, center, or right
- whether text is bold, italic, uppercase, or underlined
The goal is simple: make text clear and comfortable to read.
Font family
The font-family property tells the browser which font to use.
You usually write more than one font name. This list is called a font stack. The browser tries the first font. If that font is not available, it tries the next one.
The last value should be a generic font family, such as sans-serif, serif, or monospace.
If a font name has spaces, wrap it in quotes:
Use one or two font families on a page. Too many fonts can make a design feel messy.
Font size
The font-size property controls how large text appears.
Two beginner-friendly units are px and rem.
pxgives a fixed size.remscales from the root font size of the page.
In many browsers, 1rem is usually 16px, so 2rem is usually 32px.
Prefer rem for text sizes. If a visitor increases their browser's default font size for readability, rem text scales with it, but px text stays fixed.
Use readable text sizes. Very small body text is hard to read, especially on phones.
Line height
The line-height property controls the vertical space between lines of text.
Think of it as breathing room inside a paragraph.
A unitless value like 1.6 is common. It means the line height is 1.6 times the current font size.
Low line height can make paragraphs feel crowded. A value around 1.5 or 1.6 is often easier to read for body text.
Text alignment
The text-align property controls how text lines up horizontally.
Common values include:
left: aligns text to the leftcenter: centers textright: aligns text to the rightjustify: stretches lines so both edges line up
Center alignment works well for short headings.
For long paragraphs, left alignment is usually easier to read. Centered paragraphs make it harder for the eye to find the next line.
Simple text formatting
CSS also has properties for simple text formatting.
Useful formatting properties:
font-weight: controls boldness, such asnormalorboldfont-style: controls slant, such asnormaloritalictext-transform: changes casing, such asuppercase,lowercase, orcapitalizetext-decoration: adds or removes lines, such asunderlineornone
Be careful with underlines. On the web, underlined text usually means a link.
Runnable example: article card typography
This example combines font family, font size, line height, alignment, and text formatting.
Try changing the CSS values and run the example again.
<article class="article-card">
<p class="category">CSS basics</p>
<h2>Learning web typography</h2>
<p class="summary">
Clear text helps visitors read your page without effort. Good font size and line height can make
a simple article feel more polished.
</p>
<a href="#">Read more</a>
</article>
<style>
.article-card {
max-width: 420px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
font-family: Arial, Helvetica, sans-serif;
}
.category {
font-size: 0.8rem;
font-weight: bold;
text-transform: uppercase;
color: #666;
}
.article-card h2 {
font-size: 1.8rem;
line-height: 1.2;
}
.summary {
font-size: 1rem;
line-height: 1.6;
text-align: left;
}
</style>The card uses one font stack, a larger heading, readable paragraph spacing, and uppercase category text.
Common beginner mistakes
- Using too many fonts: One or two font families is usually enough.
- Forgetting fallback fonts: End a font stack with a generic family like
sans-serif. - Making text too small: Body text should be comfortable to read.
- Using tight line height: Paragraphs need enough vertical space.
- Centering long paragraphs: Center alignment is better for short text.
- Underlining normal text: Underlines can make regular text look clickable.
Mini task
Look at this CSS:
Which property should you add if you want more vertical breathing room between lines of text?
Check the quiz answers below when you are ready.
Short quiz with answers
- Which CSS property chooses the font?
- If the root font size is
16px, what size is2rem? - Why should
"Times New Roman"be wrapped in quotes?
Answers:
font-family.32px.- Because the font name contains spaces.
Mini task answer: add line-height.
Small challenge
Style the profile text below.
Your goals:
- Set a
sans-seriffont stack on.profile. - Make the name uppercase.
- Make the name normal weight.
- Give the paragraph a comfortable line height.
<div class="profile">
<h3 class="name">Jane Doe</h3>
<p class="bio">I am learning how typography makes text easier to read on the web.</p>
</div>
<style>
.profile {
}
.name {
}
.bio {
}
</style>One possible solution:
Summary
font-familychooses the font and should include fallback fonts.font-sizecontrols how large text appears.line-heightcontrols vertical space between lines.text-aligncontrols horizontal text alignment.font-weightchanges boldness.font-stylecan make text italic.text-transformchanges text casing.text-decorationadds or removes lines, such as underlines.