Chapter 7 of 17 · CSS for Beginners — Complete Free Tutorial

CSS Typography

Most of a website is text. Typography is therefore the highest-leverage skill in CSS: font choice, size, spacing and measure decide whether reading feels effortless or exhausting.

Font families

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
}

The list is a fallback chain: the browser uses the first font installed on the user's device, then the next, ending in a generic sans-serif. Named fonts must be quoted when they contain spaces.

CategoryExamplesNotes
Sans-serifsystem-ui, Arial, HelveticaUI, screens, modern brands
SerifGeorgia, "Times New Roman"Articles, editorial feel
Monospace"JetBrains Mono", "SF Mono"Code, data, terminal

Loading web fonts

Self-host or use a privacy-friendly CDN (this site uses Bunny Fonts), then declare the family:

@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 600;
  font-display: swap;
}

font-display: swap shows fallback text immediately and swaps in the real font when ready — never leave users staring at nothing.

Size and scale

body  { font-size: 1rem; }        /* base: 16px by default */
h1    { font-size: 2.25rem; }
h2    { font-size: 1.75rem; }
small { font-size: 0.875rem; }

Use rem (relative to the root font size) so the whole page respects a user's browser settings — a core accessibility habit. Keep a simple ratio (for example ×1.25) between heading levels; avoid jumping from 16 px straight to 40 px.

Line height and spacing

p        { line-height: 1.7; }         /* unitless = multiplier */
h1       { line-height: 1.15; letter-spacing: -0.02em; }
p + p    { margin-top: 1em; }
  • Prefer unitless line-height — it multiplies each element's own font size instead of freezing one pixel value.
  • Body copy likes 1.5–1.8; headings tighten to 1.1–1.3.
  • A slight negative letter-spacing makes big headings look tighter and more premium.

Text properties cheat sheet

PropertyControlsExample
font-weightBoldness700 / bold
font-styleItalicsitalic
text-alignHorizontal alignmentcenter, justify
text-transformCaseuppercase
text-decorationUnderlines etc.underline dotted
text-overflowEllipsis on overflowellipsis (needs nowrap + overflow:hidden)
word-break/overflow-wrapLong-word wrappingbreak-word
max-width: 65chReadable line length≈ 65 characters per line

Truncating text with an ellipsis

.card__title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

Expected output: long titles cut off with "…" inside their container. All three properties are required (and the element must be block-level with a constrained width).

A complete article style

.article {
  font-family: Georgia, "Times New Roman", serif;
  max-width: 65ch;
  font-size: 1.125rem;
  line-height: 1.75;
  color: #1e293b;
}
.article h2 {
  font-family: system-ui, sans-serif;   /* headings switch to sans */
  font-size: 1.6rem;
  line-height: 1.25;
  margin-top: 2.2em;
}
.article a {
  color: #4f46e5;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.article code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9em;
  background: #f1f5f9;
  padding: 0.1em 0.35em;
  border-radius: 0.3em;
}

Expected output: a serif reading column with sans-serif headings, comfortable spacing, indigo links and tinted inline code — the pattern used by blogs and docs worldwide.

Common mistakes

  • px everywhere — px ignores user font preferences; use rem for sizes.
  • Tight line-height on paragraphs — 1.0 on multi-line text is unreadable.
  • Long unbreakable lines — cap with max-width: 65ch; without it, lines run 200 characters.
  • Justified text with text-align: justify — rivers of white space appear on the web; prefer left-aligned.
  • Loading five font weights — each is a network request; ship only what you use.

Practice checklist

  1. Style a paragraph block: rem sizes, 1.75 line-height, max-width: 65ch.
  2. Add a drop cap with ::first-letter (from the pseudo-elements chapter).
  3. Shrink your browser's font size (Cmd/Ctrl + minus) — your layout should adapt, not break.

Under text sits the box everything lives in — The Box Model is next, and it changes how you see every element.

Quiz: CSS Typography

5 questions · 70% to pass

Frequently Asked Questions

CSS (Cascading Style Sheets) is the language that controls how HTML content looks — colours, fonts, spacing, layout, responsiveness and animation. HTML provides structure and meaning; CSS provides presentation. One stylesheet can restyle an entire website at once.

The fundamentals (selectors, box model, Flexbox, media queries) take about 2–3 weeks of daily practice. Grid, animations and architecture come with a little more practice. This 17-chapter series is designed for 3–4 weeks at a relaxed pace — faster if you type out every example.

Yes. HTML first, then CSS, then JavaScript. CSS and HTML together let you build complete, good-looking static pages, and almost every JavaScript framework assumes you already know CSS layout and selectors.

No — CSS is a styling language with selectors and property-value declarations, not variables, loops or conditionals. You can get far without any programming logic, and JavaScript adds the behaviour later.

Flexbox distributes space along one axis (a row or a column) and is ideal for components — toolbars, navbars, card rows. Grid controls rows and columns together and is ideal for page structure and card grids. They are complementary: many layouts use a grid page shell with flex components inside.

Usually one of three reasons: the selector does not match (check class names), a more specific rule wins (use the browser inspector to see computed styles and specificity), or the file is not linked/loads in the wrong order. The specificity chapter explains how the cascade decides.

Every element is a box of four layers: content, padding (inner space), border, and margin (outer space). With box-sizing: border-box, the width you set includes padding and border — the universal reset every project uses.

Use relative units, flexible grids like repeat(auto-fit, minmax(260px, 1fr)), images with max-width: 100%, and mobile-first media queries. The goal is zero horizontal scrolling from 320px up — the responsive chapters show the full workflow.

Not to learn. Frameworks are productivity tools built on the same CSS you are learning here; understanding the fundamentals makes any framework easier to use (and to debug when it fights you). Learn vanilla CSS first, then evaluate frameworks with an informed eye.

JavaScript for interactivity, then a build tool and version control (Git). With HTML, CSS and JavaScript you can build complete websites; after that, frameworks like React or server-side tools like Laravel Blade build on these fundamentals.