CSS Fonts

Font family, size, weight, style and web fonts.

✍️ 3 exercises + code challenge in this lesson

Font properties control the typeface of your text:

  • font-family: a list of fonts, ending with a generic family like sans-serif, serif or monospace.
  • font-size: e.g. 16px, 1.25rem.
  • font-weight: normal, bold or 100–900.
  • font-style: normal or italic.

Web fonts

Services like Google Fonts let you use thousands of fonts. Link the font in your HTML, then use its name in font-family.

Use rem for font sizes. It respects the user's browser settings and scales well.

Key Takeaways: CSS Fonts

Mastering CSS Fonts helps you write clean and reliable CSS code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

CSS Fonts Code Example

CSS
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;800&display=swap" rel="stylesheet">
<style>
  .serif { font-family: Georgia, "Times New Roman", serif; font-size: 1.3rem; }
  .mono  { font-family: "Courier New", monospace; }
  .web   { font-family: "Poppins", sans-serif; font-weight: 800; font-size: 2rem; color: #071A2F; }
  .light { font-weight: 300; font-style: italic; }
</style>

<p class="serif">A serif font (Georgia)</p>
<p class="mono">A monospace font</p>
<p class="web">Poppins from Google Fonts</p>
<p class="light">Light and italic</p>
Free sign-in required · Google login available

CSS Fonts Practice Exercises

Check what you learned in “CSS Fonts”.

/ 3 solved
Fill in the blank

Make the text bold.

p {
  font-weight: ;
}
✓ Correct! Not quite. Try again.
Multiple choice

Why should a font-family list end with a generic family like sans-serif?

✓ Correct! Not quite. Try again.
Code challenge

Make the paragraph italic and 18px.

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services