Your page has a palette now: a named background, a hex heading, an rgb section colour. The letters themselves still sit in whatever font your browser happens to default to. This lesson gives your name, your headings, and your bio a real typographic pass.
The concept
Here is your page as it stands, palette and all. Run it:
▸WHAT'S ALREADY IN THIS PAGE
New here? This starter already carries the standard HTML frame. You do not need to change it to do the exercise — each piece is taught in its own lesson.
<!DOCTYPE html>— Tells the browser to use modern rendering rules. Taught in lesson 2.<html> … </html>— The root element that wraps the whole document. Taught in lesson 2.lang="en"— Sets the page's language. Taught in lesson 6.<head>— Holds information about the page; nothing in it is drawn on screen. Taught in lesson 2.<meta charset="UTF-8" />— Sets how the browser decodes the text. Taught in lesson 6.<title>— Sets the browser-tab text. Taught in lesson 2.<body>— Holds everything a visitor actually sees. Taught in lesson 2.
The "where you left off" demos show the placeholder version of the page. Your own page, with your real content, is safe in the exercise below.
Fonts work differently from colours. A colour you write always renders. A font you name might not even be installed on the visitor's computer. Watch what the browser does about that. Run this:
Your heading renders in a plain, evenly spaced typeface, the kind used for code. "TotallyMadeUpFontName" does not exist anywhere, on any computer. The browser skips it and moves on to monospace, the next name in the list. That list is a font stack: preferences in order, ending in a generic family every browser is guaranteed to have.
Now see what a full typographic pass does to an ordinary page. Here is one before any of it. Run it:
Here is the same markup, after four small rules. Run it:
Nothing was added or removed. The same name, the same heading, the same sentence, now with a chosen typeface, a bigger name, lighter headings, and paragraphs with room to breathe.
The syntax
A font stack lists names from most to least preferred. It ends in a generic keyword such as serif, sans-serif, or monospace. Quote a name that contains a space:
body {
font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
}Setting font-family on body reaches your whole page. Text properties like this one are inherited. Every element inside body, including h1, h2, and p, picks it up unless a more specific rule overrides it.
font-size controls how large text renders, commonly in rem units:
h1 {
font-size: 2.5rem;
}A rem is relative to the page's root size. That size defaults to 16 pixels in most browsers, so 2.5rem works out to 40 pixels.
line-height controls the space a line of text occupies. Write it as a plain number, with no unit. That number multiplies the element's own font-size.
p {
line-height: 1.6;
}font-weight controls how thick a typeface's strokes render. It takes a number, or a keyword:
h2 {
font-weight: 500;
}Weight values commonly run in steps of 100, from 100 up to 900. Headings render bold by default, around 700. A lower number such as 500 or 600 lightens that default on purpose.
A minimal working example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Typography</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<h1>Your Name</h1>
</body>
</html>body {
font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
}
h1 {
font-size: 2.5rem;
}One stack, one size, one heading that looks deliberately chosen instead of left as a default.
Common mistakes
Your paragraph reads like each line was set adrift from the next. An extreme line-height does this. Run it:
line-height: 4 gives each line four times its own height of space. A little room helps reading. This much space breaks the paragraph apart instead.
Your custom font never seems to apply, and nothing about the page looks wrong either. Compare this heading to the monospace one from earlier in the lesson:
No monospace, no fallback at all. The made-up name still fails to match anything. This time the browser lands on its own plain default, instead of the distinctive fallback you asked for. The result looks ordinary, which is exactly the problem. Nothing marks it as broken, and what a visitor actually sees is now out of your hands.
You add a unit to font-weight out of habit, since font-size and line-height both take one. Run it:
font-weight takes a plain number or a keyword, never a length. 900px is invalid, so the whole declaration is dropped and the heading keeps its previous weight. Not every property accepts the same shape of value.
Try it yourself
Your page still uses whatever font your browser defaults to. Give it a real typographic pass. After each Run, scroll the preview to Skills or Contact if you do not see those headings yet.
- Run the starting code below. Confirm your name, headings, and bio all render in your browser's default typeface.
- On
body, addfont-family: 'Segoe UI', Helvetica, Arial, sans-serif;. Run it. Confirm every piece of text on the page shifts to this typeface at once. - On
h1, addfont-size: 2.5rem;. Run it. Confirm your name renders noticeably larger than before. - On
p, addline-height: 1.6;. Run it. Scroll the preview to Contact if you do not see it yet. Confirm your bio and contact paragraphs gain visible space between their lines. - On
h2, addfont-weight: 500;. Run it. Scroll if you need to. Confirm About, Skills, and Contact all look lighter than the default bold heading. - Break it on purpose: change the
prule'sline-heightto4. Run it. Confirm your paragraphs scatter into widely spaced lines. - Fix it: change that
line-heightback to1.6. Run it. Confirm your bio reads normally again.
▸WHAT'S ALREADY IN THIS PAGE
New here? This starter already carries the standard HTML frame. You do not need to change it to do the exercise — each piece is taught in its own lesson.
<!DOCTYPE html>— Tells the browser to use modern rendering rules. Taught in lesson 2.<html> … </html>— The root element that wraps the whole document. Taught in lesson 2.lang="en"— Sets the page's language. Taught in lesson 6.<head>— Holds information about the page; nothing in it is drawn on screen. Taught in lesson 2.<meta charset="UTF-8" />— Sets how the browser decodes the text. Taught in lesson 6.<title>— Sets the browser-tab text. Taught in lesson 2.<body>— Holds everything a visitor actually sees. Taught in lesson 2.
Your name, headings, and bio now carry a deliberate typeface, size, spacing, and weight, instead of a browser's default guess. The next lesson turns to space itself: margin, padding, and border around every section on the page.