CSS font-size Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The font-size property sets how large text is drawn. Changing it also updates font-relative lengths such as em and ex on that element.

You can use absolute keywords (medium, large), relative keywords (larger, smaller), lengths (1rem, 16px), or percentages. The property is inherited. Pair it with font-family and line-height for readable type.

Baseline · Widely available.

Not deprecated and not experimental. Prefer relative sizes such as rem when you want text to respect user font preferences.

CSS Syntax

syntax.css
font-size: <absolute-size> | <relative-size> | <length-percentage> | initial | inherit;

The initial value is medium. Length and percentage values must be non-negative.

Property Values

ValueDescriptionTry it
<length> (rem)Size relative to the root html font sizeTry it
<length> (px)Fixed pixel sizeTry it
large (keyword)Absolute-size keyword based on the user default (medium)Try it
<percentage>Percent of the parent element’s font sizeTry it
emMultiplier of the parent’s font size (can compound when nested)Try it
inheritUses the parent’s font-sizeTry it

How to Use font-size

Pick a unit that matches your goal, then apply it on the element that should change size.

  1. Decide the goal: scale with the root (rem), follow the parent (em / %), or use a fixed pixel size.
  2. Set font-size on the element (or on html / body for a page-wide base).
  3. Check nested text — em and % multiply through parents; rem does not.
  4. Keep body text readable; adjust headings and UI labels from that base.
PieceRequired?Role
A size valueYesKeyword, length, or percentage
Text contentYesSomething visible to size
Root / parent sizeFor rem / emReference for relative units
line-heightRecommendedKeeps multi-line text readable at the new size

Live Preview

Change only font-size on the sample sentence. Everything else stays the same.

Relative values use the page root or parent size. Absolute keywords follow the user default scale.

Sample

The quick brown fox jumps over the lazy dog.

font-size: 1.25rem

CSS Examples

Each snippet focuses on font-size. Use Try It Yourself for a live editor.

Example 1 — Size with rem

Root-relative size that stays predictable when nested.

CSS
<style>
  p {
    font-size: 1.25rem;
  }
</style>

<p>Text sized with rem.</p>
Try It Yourself

How It Works

  1. Target the text. The rule applies to the paragraph.
  2. Use the root. 1.25rem means 1.25 × the html font size (often 16px → 20px).
  3. Stay stable when nested. Children that also use rem do not multiply against this paragraph.
  4. Why students use it. One root size can scale body and UI type together.

Example 2 — Absolute Keyword

Keywords sit on a scale based on the user’s default medium size.

CSS
<style>
  p {
    font-size: large;
  }
</style>

<p>Text sized with the large keyword.</p>
Try It Yourself

How It Works

  1. Skip a number. large is an absolute-size keyword, not a pixel count.
  2. Anchor on medium. Browsers map keywords around the user’s default medium size.
  3. Step the scale. Nearby values include small, medium, x-large, and others.
  4. Relative cousins. larger / smaller bump size relative to the parent instead.

Example 3 — Relative em

em multiplies the parent size — nested spans can grow quickly.

CSS
<style>
  span {
    font-size: 1.5em;
  }
</style>

<p>Outer <span>middle <span>inner</span></span></p>
Try It Yourself

How It Works

  1. Read the parent. Each 1.5em is 1.5 × that span’s parent font size.
  2. Nest and multiply. The inner span is 1.5 × the middle span, so it grows again.
  3. Compare with rem. The same nesting with rem would keep every span the same size.
  4. When to use em. Useful when a piece of text should scale with its local container, not the whole page.

Edge Cases & Pitfalls

If text looks too big, too small, or inconsistent, check these first.

em

em compounds in nested elements

A nested 1.5em inside another 1.5em becomes much larger than you might expect. Prefer rem when you want stable sizing.

px

Fixed px can hurt accessibility

Some browsers do not let users rescale text set only in pixels. Prefer relative units for body copy when inclusive design matters.

%

Percentages use the parent size

font-size: 150% means 1.5 × the parent’s font size, not 150% of the viewport.

shorthand

font can reset size

The font shorthand sets size and can overwrite a earlier font-size rule. Put size after the shorthand, or include it in the shorthand.

zero

Negative sizes are invalid

Length and percentage values must be zero or positive. A negative font-size is ignored.

Browser Support

font-size is a browser CSS property for text sizing. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

font-size

Supported in all modern browsers and Internet Explorer. Core keyword, length, and percentage values are universal.

100% Modern browser support
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer All
Full support
font-size Widely supported

Bottom line: Safe to use everywhere. Prefer rem or other relative sizes for accessible body text. It is not a runtime API.

Key Takeaways

  • Role: set the size of text (and related em/ex units).
  • Prefer rem: predictable scaling from the root without nesting surprises.
  • em / %: relative to the parent and can compound when nested.
  • Initial value: medium. Inherited by default.

One line: font-size: 1.25rem; sizes text from the root in a way that stays easy to scale.

Frequently Asked Questions

It sets the size of text for an element. Changing it also updates font-relative units such as em and ex on that element.
The initial value is medium. Browsers usually treat medium body text as about 16px when the user has not changed preferences.
Prefer rem (or other relative sizes) for most text so size can scale with the root and user settings. Use px when you need a fixed pixel size for a small UI detail.
em is relative to the parent’s font size and can compound inside nested elements. rem is relative to the root html font size, so nesting does not multiply the size.
Yes. Children inherit the computed size unless they set their own font-size.
It is Baseline Widely available and works in all modern browsers and Internet Explorer. It is a browser CSS property, not a Node.js feature.

Next: font-size-adjust

Preserve readable size when the browser switches to a fallback font.

font-size-adjust tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful