← Level 1 – Builder

Lesson 7 of 12 ⏱ 25 minutes

Fonts and classes

Pick a proper font for your website, and learn about classes – the most useful trick in all of CSS.

Show me: a nicer font

The browser’s default font is boring. Let’s swap it out with one rule for the whole page:

body {
  font-family: Verdana, Arial, sans-serif;
}

font-family is a wish list: “Use Verdana. Don’t have it? Then Arial. Not that either? Then any sans-serif font (sans-serif).”

Fonts nearly every computer has: Verdana, Georgia (has little feet, good for longer text), Trebuchet MS, Courier New (looks like a typewriter). Try a few out – changing the font works wonders on a website.

Show me: classes

So far you can style every paragraph at once. But what if one paragraph needs to look different – like an important notice? That’s what classes are for:

In HTML, give a tag a class name:

<p class="notice">No school tomorrow!</p>

And in CSS, target it with a dot:

.notice {
  background-color: #fef3c7;
  border: 2px solid #f59e0b;
  padding: 10px;
  border-radius: 8px;
}

You can put a class on as many elements as you like – they’ll all dress the same way. It’s like a school uniform, but for tags.

Your turn 💪

  1. Set a font for your whole website using font-family on body.
  2. Come up with at least one class that fits your project, and use it in two places.
🏫 School website – solution (a "news" class)
<p class="news">📢 No school on Friday – teacher training day!</p>
<p class="news">📢 Paper drive starts Monday.</p>
body {
  font-family: Verdana, Arial, sans-serif;
}

.news {
  background-color: #fef3c7;
  border: 2px solid #f59e0b;
  padding: 10px;
  border-radius: 8px;
}
🙋 Personal website – solution (a "favorite" class)
<p class="favorite">⭐ Favorite game: Minecraft</p>
<p class="favorite">⭐ Favorite food: pancakes</p>
body {
  font-family: "Trebuchet MS", Verdana, sans-serif;
}

.favorite {
  background-color: #ffedd5;
  border: 2px solid #ea580c;
  padding: 10px;
  border-radius: 8px;
}
🌍 Travel journal – solution (a "tip" class)
<p class="tip">🎒 Trip tip: head up the mountain early, before it gets hot.</p>
<p class="tip">🎒 Tip: bring water shoes to the beach!</p>
body {
  font-family: Georgia, "Times New Roman", serif;
}

.tip {
  background-color: #dcfce7;
  border: 2px solid #16a34a;
  padding: 10px;
  border-radius: 8px;
}
⚽ Club website – solution (a "win" class)
<li class="win">Eagles – Hawks 3 : 1</li>
<li>Falcons – Eagles 2 : 2</li>
<li class="win">Eagles – Wildcats 4 : 0</li>
body {
  font-family: Verdana, Arial, sans-serif;
}

.win {
  background-color: #dcfce7;
  font-weight: bold;
}

Wins get highlighted in green right away – just like in a real standings table!

Check yourself: Your website has a new font, and at least one element with its own class that looks different from the rest.

What to take away from this lesson