OnlineCBT Logo OnlineCBT
CSS Tutorial
CSS · LESSON 16

Typography and Web Fonts (Google Fonts)

By Ratan Updated: 15 Oct 2026

Style body text with font-family, font-size, font-weight, line-height, and embed Google Fonts.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Make reading comfortable before choosing a decorative font

Typography combines family, size, weight, line height and line length. A good default remains readable when a web font fails to load, when text is translated, and when the user zooms.

.tech-lesson-content {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  color: #0f172a;
}
.article { max-width: 65ch; margin-inline: auto; }
h1 { font-size: 2rem; line-height: 1.2; }
button, input, select, textarea { font: inherit; }

The unitless line-height scales with each element's font size. The ch-based maximum width is an approximate reading measure, not a fixed character count for every language. Test actual Hindi and English paragraphs rather than assuming identical metrics.

Using a web font

A provider such as Google Fonts supplies a stylesheet link generated for the chosen family, weights and scripts. Put that link in the document head and declare the selected family with a fallback. Alternatively, self-host a properly licensed font file:

@font-face {
  font-family: "Lesson Sans";
  src: url("fonts/lesson-sans.woff2") format("woff2");
  font-display: swap;
}
.article { font-family: "Lesson Sans", system-ui, sans-serif; }

Replace the example path with an actual licensed file. swap allows fallback text while the font loads. Different metrics can shift layout when the font replaces the fallback, so reserve space and compare the two.

Load only what you need

Requesting many families, weights and language subsets increases download cost. Confirm the font includes Devanagari if you display Hindi. Do not fake meaningful bold hierarchy by using only a decorative thin font. A remote font request also creates a third-party dependency; choose hosting according to the project's privacy and performance needs.

Practice

  1. Compare paragraphs at line-height 1.2 and 1.6.
  2. Disable the web-font request and check fallback layout.
  3. Zoom to 200% and verify headings do not clip.
  4. Make form controls inherit the body font and compare their alignment.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat