Text & FontsCore· 35 min read

Fonts

Choose typefaces, sizes and weights — and always provide a fallback.

What you will learn

  • Set font-family with fallbacks
  • Control font-size, weight and style
  • Use the font shorthand

font-family and the fallback stack

List fonts in order of preference. The browser uses the first one available, falling back to the next. End with a generic family (sans-serif, serif).

A font-family fallback stack
<style>
  .sans { font-family: Arial, Helvetica, sans-serif; }
  .serif { font-family: Georgia, 'Times New Roman', serif; }
  p { font-size: 18px; margin-bottom: 6px; }
</style>
<p class="sans">Sans-serif: clean and modern.</p>
<p class="serif">Serif: classic and formal.</p>
Live preview

The comma-separated list in font-family is a fallback stack — a list of preferences. For .sans the browser tries Arial first; if Arial is missing it tries Helvetica; if that is gone too it uses any sans-serif font the device has. The .serif stack works the same way, ending in the generic serif. Always end with a generic family (sans-serif or serif) so the page never falls back to nothing.

Size, weight and style

PropertyValues
font-size16px, 1.2rem, 2em
font-weightnormal, bold, 100900
font-stylenormal, italic
Size, weight and style
<style>
  .big { font-size: 28px; font-weight: 700; }
  .quote { font-style: italic; color:#5b6178; }
</style>
<p class="big">Big and bold (700)</p>
<p class="quote">Italic for a quote</p>
Live preview

.big combines two properties: font-size: 28px makes the text large and font-weight: 700 makes it bold (700 is the same as bold; the scale runs 100–900). .quote uses font-style: italic to slant the text, which reads as a quotation. These three — size, weight and style — are the everyday controls for emphasis.

Note: Web-safe fonts (Arial, Georgia, Times, Courier) are installed on almost every device. For custom designer fonts, use Google Fonts — the next lesson.

Q. Why end a font-family list with sans-serif or serif?

Answer: The generic family is the final fallback, guaranteeing the browser uses a sensible default if none of your named fonts are available.

✍️ Practice

  1. Set a sans-serif font stack on your whole page body.
  2. Make headings bold and large, and a quote italic.

🏠 Homework

  1. Pick a font pairing (one for headings, one for body) and apply it to your profile page.
Want to learn this with a mentor?

CodingClave runs guided, project-based training (28-day, 45-day & 6-month batches).

Explore Training →