designwithfocus

Web design basics

What Is Web Typography? Type That Holds Up On Screen

By Design With Focus Team 6 min read
A paragraph of type between a small size and a large size on a screen

Short answer

Web typography is the setting of type so it stays readable on a screen, using CSS properties rather than a fixed print layout. font-size sets the size and is inherited. line-height sets the line box, and a unitless number is the value MDN prefers. font-family chooses the face and is also inherited. clamp() can grow a size with the viewport while holding a minimum and a maximum.

Last verified against the sources listed below.

Key takeaways

  • font-size is inherited. MDN says relative units respect a reader's default better than px.
  • If the root is 16px, 1rem is 16px. 12px as em is 12 divided by 16, which is 0.75em.
  • em compounds. 1.6em inside 1.6em becomes 40.96px when the root is 16px.
  • Prefer a unitless line-height. MDN asks for at least 1.5 on main paragraphs.
  • clamp(min, val, max) resolves as max(min, min(val, max)). The max should be at least twice the min when you scale text.

What is web typography? It is type set with CSS so a page stays readable when the screen, the zoom, and the reader’s default size all change.

The core properties are font-size, line-height, and font-family. A fluid size uses clamp() between a floor and a ceiling.

Print layout can lock a block of metal or a fixed text box. On the web, the same paragraph has to survive a narrow phone and a reader who enlarged the default. The properties below are how the specs and MDN describe that job.

Web typography guide

Set a relative size, a unitless line height of at least 1.5 for body copy, and a font stack that ends in a generic family.

font-size sets the size and updates font-relative units such as em. It is inherited. The initial value is medium.

Percentages refer to the parent. MDN says relative values are the more accessible choice, because they follow the user’s default. The property has been available across browsers since July 2015, with some newer pieces varying.

line-height sets the line box. A unitless number is multiplied by the element’s own font size, and that number is what gets inherited. MDN prefers it so a child does not inherit a length that was computed for a different size.

The accessibility note asks for a minimum of 1.5 on main paragraphs. Desktop browsers use roughly 1.2 for the keyword normal, depending on the family. The property has also been available since July 2015.

CSS Fonts Level 4 says the face used for a character comes from the family plus the other font properties, and that those settings can vary independently. font-family is inherited, applies to all elements and text, and its initial value depends on the user agent.

How do the size units differ?

rem follows the root. em follows the parent and compounds. px is a fixed length MDN treats as a poor default for body text.

MDN says that if no ancestor sets a size, 1em equals the browser default, which is usually 16px. Then 2em is 32px.

The conversion it prints is: em equals the desired pixel value divided by the parent font size in pixels. For a 16px parent, 12px is 0.75em, because 12 divided by 16 is 0.75. 22px is 1.375em.

em compounds. With the root at the usual 16px and a span at 1.6em, the outer words render at 25.6px. An inner span at 1.6em of that parent renders at 40.96px.

rem was added to avoid that chain. 1.6rem on both spans stays 25.6px when the root is 16px, because both measure the root, not each other.

Property or unit What it follows A number MDN states
font-size initial The user’s medium medium, not a pixel lock
1em with no ancestor size Browser default Usually 16px
12px at a 16px parent Parent size 0.75em
Nested 1.6em from 16px Parent, then parent again 25.6px, then 40.96px
line-height normal The family, via the browser Roughly 1.2 on desktop
Body line-height The element’s own font size At least 1.5 for main paragraphs

When should size scale with the viewport?

Use clamp() when the size should grow with the window and still stop at a floor and a ceiling.

clamp() takes a minimum, a preferred value, and a maximum. MDN says it resolves as max(MIN, min(VAL, MAX)).

For type, the preferred piece is often a viewport unit, and the ends are rem so they track the root. The function has been available since July 2020. The page says this replaces a fluid-type pattern that used to need media queries.

One example is clamp(1rem, 2.5vw, 2rem). If 2.5vw is below 1rem, the size is 1rem. If it is above 2rem, the size is 2rem.

The accessibility note says the maximum should be a relative length at least twice the minimum, so zoom can still reach 200 percent. In that example, 2rem is twice 1rem. A heading example on the same page uses clamp(1.8rem, 2.5vw, 2.8rem).

What does a family name change?

It changes the face, not the size and not the line height. Those stay on their own properties.

A stack lists specific names first and a generic last, so a missing file still yields serif or sans-serif.

The Poppins specimen is one family a stack might name. Its page lists Thin 100 through Black 900, each with an italic.

Naming it in font-family does not set 1.5 line-height for you. You still declare that.

The SIL Open Font License site says OFL 1.1 is the license written for fonts, unchanged in its terms since 2007, and that OFL fonts can be used on websites. Whether a given family is under that license is a fact on that family’s page, not a CSS initial value. The CSS Fonts spec does not pick a foundry.

What should you set first?

Set the root size, then body line-height, then a heading clamp, then the family stack.

  1. Leave the root at the user’s default, or set it with a percentage or rem, not a locked px on every element.
  2. Set body line-height to a unitless 1.5 or more.
  3. Use rem for sizes that should not compound. Use em only when you want a size tied to its parent.
  4. Put fluid headings in clamp(), with a relative maximum at least twice the minimum.
  5. End font-family with a generic. Load only the weights you will actually use.

Check the arithmetic before you ship a nested em. If the parent is 16px and the child is 1.6em, the child is 25.6px.

A second 1.6em inside it is 40.96px. That jump is the compounding MDN walks through, not a browser bug.

Kerning is the space between a specific pair of letters. Size and line-height do not set that pair adjustment.

CSS is the language these properties belong to. The numbers above are the ones MDN and the font spec publish.

The Fluid Typography calculator builds a clamp() font-size between two viewports. It does not choose your font-family or your line-height.

Frequently asked questions

Why does MDN warn against font-size in px?

Because a px font size is static, and MDN says users cannot change it in some browsers. People who need larger type can be stuck with the designer's number. The initial value of font-size is medium, which tracks the user's default. Keywords such as small and large, and relative units such as rem, scale from that default. For body text, start from the user's size instead of locking pixels.

What line-height number should body text use?

MDN's accessibility note says to use at least 1.5 for main paragraph content, which helps low vision and some cognitive needs. A unitless number stays proportional when the page is zoomed. The initial value normal is up to the browser, and desktop browsers including Firefox use roughly 1.2, depending on the font-family. A length or a percentage can surprise you after inheritance, so the page prefers a unitless number.

How does clamp differ from a media query?

clamp takes a minimum, a preferred value, and a maximum, and it picks the preferred value only while that value sits between the other two. MDN says using it for font-size has the same effect as fluid type that would otherwise need media queries, in one declaration. The function has been available across browsers since July 2020. An example on the page is clamp(1rem, 2.5vw, 2rem).

Does font-family inherit?

Yes. CSS Fonts Module Level 4 lists font-family as inherited, applying to all elements and text, with an initial value that depends on the user agent. The computed value is a list of names and keywords. If the first family is missing, the browser continues down the list, which is why a stack ends in a generic such as serif or sans-serif. Family does not set the size or the line height.

Are web fonts a different CSS property?

The family name is still font-family, whether the face is installed or downloaded. A license is a separate fact about the font file, not a CSS value. The SIL site describes OFL 1.1 as a license made for fonts, and those fonts can be used on websites. That permission is about the file, not your line-height. Read the license that ships with the family, then set size and line height in CSS.

Sources