Support0

CSS font-size playground

Explore font-size with controls for comparing browser keywords, relative values, and lengths on a real text block.

Ask AI

CSS font-size playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.

BaselineLab lets you compare font-size with real text, relative values, browser keywords and fixed lengths before using them in CSS. Adjust the size and observe how readability changes while preserving the rhythm of the block.

HTML
<p class="font-size-sample">
  BaselineLab lets you compare font-size with real text,
  relative values, browser keywords and fixed lengths before using them in CSS.
  Adjust the size and observe how readability changes while preserving the rhythm of the block.
</p>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<p class="max-w-xl leading-normal text-xl">
  BaselineLab lets you compare font-size with real text,
  relative values, browser keywords and fixed lengths before using them in CSS.
  Adjust the size and observe how readability changes while preserving the rhythm of the block.
</p>
CSS
.font-size-sample {
  max-inline-size: 36rem;
  font-size: 1.25rem;
  line-height: 1.5;
}

Educational guide to font-size

Choose a size and its reference

Compare units, inheritance, and keywords. Build a fluid scale and check how it responds when text is enlarged.

Mental model

font-size sets the nominal font size. Two families at the same size can look different: the visible height of letters depends on their metrics. The property inherits; line-height controls the line box.

  1. Root: 16 px in this diagram

    1.25rem references the root: 1.25 × 16 = 20 px.

  2. Parent: 20 px in this diagram

    1.25em and 125% in font-size reference the parent: 1.25 × 20 = 25 px.

  3. The computed value is inherited

    Without a new declaration, a child inherits its parent’s computed size. Inheritance alone does not multiply the relative expression again.

Static diagram of size referencesA calculation example with a 16 px root and a 20 px parent. These are comparison assumptions, not universal browser values or measurements of a letter’s visible height.

Absolute and relative units

rem keeps a shared reference to the root; em and % in font-size let a component depend on its parent. px is an absolute length in CSS pixels, which do not necessarily match physical pixels.

A 1.25rem parent and five ways to size text

inherit · Text to read

1.25em · Text to read

125% · Text to read

1.25rem · Text to read

20px · Text to read

With a 16 px root, inherit, 1.25rem, and 20px yield 20 px; 1.25em and 125% yield 25 px. Increasing the root changes the relative samples; the 20px sample keeps its size in CSS pixels.
A 1.25rem parent and five ways to size text
<div class="font-size-guide-units">
  <p class="inherited">inherit · Text to read</p>
  <p class="em">1.25em · Text to read</p>
  <p class="percent">125% · Text to read</p>
  <p class="rem">1.25rem · Text to read</p>
  <p class="pixels">20px · Text to read</p>
</div>
.font-size-guide-units {
  font-size: 1.25rem;
  line-height: 1.5;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 1rem;
  }

  .inherited {
    font-size: inherit;
  }

  .em {
    font-size: 1.25em;
  }

  .percent {
    font-size: 125%;
  }

  .rem {
    font-size: 1.25rem;
  }

  .pixels {
    font-size: 20px;
  }
}

A px value can grow with page zoom even when it does not follow the default font size. Physical units such as pt (1 pt = 1/72 in) are absolute too. Start with relative units for screen reading. Outside font-size, em usually references the element’s own size; in font-size it uses the parent’s.

Inheritance and compounding

Inheriting a size preserves its computed value. Declaring 1.25em or 125% again at every level does apply another factor. rem keeps the same reference regardless of HTML depth.

The same rule applied at two levels

1.25em

First level

Second level

125%

First level

Second level

1.25rem

First level

Second level

The container starts at 1rem. With em and %, the first level is 1.25 times the root size and the second is 1.5625 times. With rem, both levels are 1.25 times the root size.
The same rule applied at two levels
<div class="font-size-guide-nesting">
  <div class="em">
    <p>1.25em</p>
    <div class="step">
      <p>First level</p>
      <div class="step">
        <p>Second level</p>
      </div>
    </div>
  </div>
  <div class="percent">
    <p>125%</p>
    <div class="step">
      <p>First level</p>
      <div class="step">
        <p>Second level</p>
      </div>
    </div>
  </div>
  <div class="rem">
    <p>1.25rem</p>
    <div class="step">
      <p>First level</p>
      <div class="step">
        <p>Second level</p>
      </div>
    </div>
  </div>
</div>
.font-size-guide-nesting {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr));
  gap: 1rem;
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 1rem;
  }

  .em .step {
    font-size: 1.25em;
  }

  .percent .step {
    font-size: 125%;
  }

  .rem .step {
    font-size: 1.25rem;
  }
}

Use em when you intend that local relationship. For a stable scale across components, rem avoids multiplication through nesting. A font-size percentage is based on the parent’s font size even if its box width changes.

Browser keywords

xx-small, x-small, small, medium, large, x-large, xx-large, and xxx-large are absolute sizes on a scale based on the user’s default size. Here, “absolute” does not mean a fixed pixel number. larger and smaller are relative to the parent.

An x-large parent and three sizing choices

inherit (x-large) · Text to read

medium · Text to read

larger · Text to read

smaller · Text to read

inherit keeps x-large. medium returns to the browser scale’s base. larger increases and smaller decreases relative to the parent; neither depends on the preceding sample.
An x-large parent and three sizing choices
<div class="font-size-guide-keywords">
  <p class="inherited">inherit (x-large) · Text to read</p>
  <p class="medium">medium · Text to read</p>
  <p class="larger">larger · Text to read</p>
  <p class="smaller">smaller · Text to read</p>
</div>
.font-size-guide-keywords {
  font-size: x-large;
  line-height: 1.5;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 1rem;
  }

  .inherited {
    font-size: inherit;
  }

  .medium {
    font-size: medium;
  }

  .larger {
    font-size: larger;
  }

  .smaller {
    font-size: smaller;
  }
}

Do not assume medium always equals 16 px or that larger adds a fixed amount. initial restores medium, while inherit takes the parent’s computed size. The final appearance also depends on the font and browser settings.

Fluid sizing with bounds

clamp(minimum, preferred, maximum) lets text grow with the viewport between two bounds. This example combines rem with vw and keeps body text at 1rem. The preview panel’s width is not the viewport.

A fluid heading and body text tied to the root

Read at your own pace

Body text keeps a stable reference while the heading adapts to the window.

The heading prefers 1.375rem + 0.5vw and stays between 1.5rem and 1.75rem. Resize the window to see the change. Changing only the guide’s width changes wrapping but leaves the vw term intact.
A fluid heading and body text tied to the root
<div class="font-size-guide-fluid">
  <p class="heading">Read at your own pace</p>
  <p>Body text keeps a stable reference while the heading adapts to the window.</p>
</div>
.font-size-guide-fluid {
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 1rem;
  }

  .heading {
    font-size: clamp(1.5rem, 1.375rem + 0.5vw, 1.75rem);
  }
}

With a 16 px root, the heading ranges from 24 to 28 px. The bounds also grow with the root. However, the viewport term can offset some zoom: including rem does not guarantee effective 200% enlargement. Test several widths and zoom levels; if text cannot reach the required size, reduce the fluid part or use rem.

Preferences and text resizing

Let the root keep the size chosen by the browser; these recipes do not set font-size on html. One rem does not always mean 16 px. Increasing the default font, resizing text only, and page zoom are different checks.

Check that text can be enlarged to 200% without losing content or actions. Also check reflow at 320 CSS pixels, equivalent in width to a 1280 px window at 400% zoom. That width equivalence does not replace testing real zoom.

Let containers grow and labels wrap; avoid fixed heights and clipping. Keep line-height unitless and browser zoom available. Test size preferences in the actual browser and device: changing the root in developer tools checks only part of the behavior.

Common pitfalls

Each level looks larger

Expected result
Nested components keep a predictable scale.
Cause
The same rule with em or % is reapplied at every level.
Solution
Declare the size once and let children inherit, or use rem when they need a shared reference.

Text barely grows when zooming

Expected result
The user can reach effective 200% text enlargement.
Cause
A size dominated by vw shrinks in CSS pixels as zoom narrows the viewport.
Solution
Combine a relative base with relative bounds; check effective growth at several widths. Use rem if the formula prevents it.

Letters or actions are clipped

Expected result
Enlarged text remains complete and operable.
Cause
A fixed height, insufficient line spacing, or clipping prevents the box growing.
Solution
Allow automatic height and wrapping; review line-height and overflow alongside the font size.

Support and compatibility

The units and keywords shown and the three-argument form of clamp() are Baseline Widely Available. Syntax support does not establish that a particular scale respects preferences or zoom.

This guide covers the playground’s values and an additional fluid recipe; it does not extend that availability to every new font-size value. Preferences, minimum sizes, and automatic text enlargement may affect the result. Check actual reading as well as the computed value.