Tutorials Logic, IN info@tutorialslogic.com

CSS Fonts font family, font size, Google Fonts: Tutorial, Examples, FAQs & Interview Tips

CSS Fonts font family, font size, Google Fonts

Text and font CSS controls how readable, scannable, and polished a page feels. Font family, size, line-height, weight, spacing, alignment, and decoration all affect how easily learners can read content.

Good typography starts with restraint. Choose clear font stacks, keep line lengths comfortable, use unitless line-height for body text, and avoid decorative effects that make reading harder.

Add one worked example that compares the normal path with the boundary case for CSS Fonts font family, font size, Google Fonts.

CSS Fonts font family font size Google Fonts should be studied as a practical CSS lesson, not as a label. Start by naming the input, the rule that changes the input, and the result a learner should be able to predict after reading the page.

In the css > text-and-fonts page, the notes should connect the definition with a working scenario, a mistake that beginners actually make, and the exact check that proves the fix. That makes the topic useful for coding, debugging, and interview revision.

Text Properties

Text properties affect the characters after the font has been chosen. They control alignment, decoration, casing, spacing, line height, truncation, and shadows.

Property Values Description
color any color Text color
text-align left | right | center | justify Horizontal alignment
text-decoration none | underline | overline | line-through Text decoration line
text-transform uppercase | lowercase | capitalize | none Case transformation
text-indent 20px | 2em First line indent
letter-spacing 2px | -1px Space between characters
word-spacing 5px Space between words
line-height 1.5 | 24px | 150% Space between lines
white-space normal | nowrap | pre | pre-wrap Whitespace handling
text-overflow clip | ellipsis Overflow text handling
text-shadow h v blur color Shadow behind text

Text Properties - Examples

Text Properties - Examples
/* Text alignment */
.center  { text-align: center; }
.justify { text-align: justify; }

/* Text decoration */
a { text-decoration: none; }           /* remove underline from links */
del { text-decoration: line-through; }
.underline { text-decoration: underline dotted red; }

/* Text transform */
.uppercase  { text-transform: uppercase; }
.capitalize { text-transform: capitalize; }

/* Spacing */
.heading {
    letter-spacing: 3px;   /* tracking */
    word-spacing: 5px;
    line-height: 1.6;      /* unitless - relative to font-size */
}

/* Text overflow - truncate with ellipsis */
.truncate {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

/* Text shadow: offset-x offset-y blur-radius color */
.shadow-text {
    text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.glow-text {
    text-shadow: 0 0 10px #3498db, 0 0 20px #3498db;
}

/* Writing mode */
.vertical { writing-mode: vertical-rl; }

/* Text indent */
p { text-indent: 2em; }

Font Properties

Font properties choose the typeface and shape of the text. Always provide fallback fonts so the page still looks acceptable if the first font fails to load.

Property Values Description
font-family 'Arial', sans-serif Font stack (fallbacks)
font-size 16px | 1rem | 1.2em | 120% Text size
font-weight normal | bold | 100-900 Thickness
font-style normal | italic | oblique Italic/oblique
font-variant normal | small-caps Small caps
font shorthand All font properties

Font Properties and Google Fonts

Font Properties and Google Fonts
/* Font family - always provide fallbacks */
body {
    font-family: 'Roboto', 'Helvetica Neue', Arial, sans-serif;
}
.code {
    font-family: 'Fira Code', 'Courier New', monospace;
}
.serif {
    font-family: 'Georgia', 'Times New Roman', serif;
}

/* Font size */
html { font-size: 16px; }   /* base size */
h1   { font-size: 2.5rem; } /* 40px */
h2   { font-size: 2rem; }   /* 32px */
p    { font-size: 1rem; }   /* 16px */
small { font-size: 0.875rem; } /* 14px */

/* Font weight */
.thin    { font-weight: 100; }
.regular { font-weight: 400; }
.bold    { font-weight: 700; }
.black   { font-weight: 900; }

/* Font shorthand: style variant weight size/line-height family */
h1 {
    font: italic small-caps bold 2rem/1.2 'Georgia', serif;
}

/* @font-face - custom fonts */
@font-face {
    font-family: 'MyFont';
    src: url('myfont.woff2') format('woff2'),
         url('myfont.woff')  format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap; /* prevents invisible text during load */
}

Font Properties

Font Properties
<!-- Google Fonts - add in <head> -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&family=Open+Sans&display=swap" rel="stylesheet">

<style>
body {
    font-family: 'Roboto', sans-serif;
    font-weight: 400;
}
h1 {
    font-family: 'Open Sans', sans-serif;
    font-weight: 700;
}
</style>

CSS Fonts font family font size Google Fonts in Real Work

CSS Fonts font family font size Google Fonts matters in CSS because it changes how a program is written, tested, or debugged. The page should explain the normal flow first: what the developer writes, what the runtime or platform does, and what result should appear.

When teaching CSS Fonts font family font size Google Fonts, avoid stopping at syntax. Show the surrounding decision: why this feature is chosen, what problem it removes, and what would become harder if the feature were not used.

  • Identify the concrete problem solved by CSS Fonts font family font size Google Fonts.
  • Show the normal input, operation, and output for css.
  • Mention the nearby alternative a beginner may confuse with this topic.
  • Tie the explanation to a real project task, command, component, query, or debugging step.

CSS Fonts font family font size Google Fonts CSS normal case

CSS Fonts font family font size Google Fonts CSS normal case
.lesson-box {
  display: block;
  max-width: 42rem;
  padding: 1rem;
}

CSS Fonts font family font size Google Fonts CSS fallback case

CSS Fonts font family font size Google Fonts CSS fallback case
.lesson-box:empty::before {
  content: "CSS Fonts font family font size Google Fonts: add visible content";
}
Key Takeaways
  • Use readable font stacks with generic fallbacks such as sans-serif or serif.
  • Use unitless line-height for body text so spacing scales with font size.
  • Keep long reading content near 60 to 75 characters per line.
  • Avoid heavy letter spacing on normal paragraph text.
  • Use font-display when loading custom fonts to reduce invisible text delays.
Common Mistakes to Avoid
WRONG Using text-align: justify on narrow mobile paragraphs.
RIGHT Use left alignment for narrow reading columns.
Justified text can create awkward word gaps on small screens.
WRONG Setting line-height in fixed pixels for all text sizes.
RIGHT Use unitless line-height like 1.6 for scalable body text.
Unitless line-height adapts when font size changes.
WRONG Using text-shadow behind small body text.
RIGHT Reserve shadows for large display text or very controlled backgrounds.
Shadows can reduce readability quickly.
WRONG Memorizing CSS Fonts font family font size Google Fonts without the situation where it is useful.
RIGHT Connect CSS Fonts font family font size Google Fonts to a concrete CSS task.
Purpose makes syntax easier to recall.

Practice Tasks

  • Create a readable article style with max-width: 65ch and line-height: 1.7.
  • Build a font stack with a custom font and safe fallbacks.
  • Create a one-line truncation style using text-overflow: ellipsis.
  • Compare letter-spacing on uppercase headings versus normal paragraphs.
  • Write a small example that uses CSS Fonts font family font size Google Fonts in a realistic CSS scenario.

Frequently Asked Questions

A unitless line-height multiplies by the element font size, so it scales naturally across headings, paragraphs, and nested text.

It is a list of preferred fonts and fallbacks, such as "Inter", Arial, sans-serif.

Use white-space: nowrap, overflow: hidden, text-overflow: ellipsis, and a constrained width.

Only when the link remains clearly recognizable through context, layout, or another visible affordance.

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.