Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

CSS Dictionary

  1. Home
  2. CSS Dictionary
  3. font-size

font-size

You can specify the font size.

Sample Code

p.test { font-size: 12px;}
p.test1 { font-size: 1.2em;}
p.test2 { font-size: 1.2rem;}
p.test3 { font-size: small;}

Available Values

ValueDescription
NumberYou can specify the font size as a number. Available units include px, pt, %, em, and rem.
KeywordYou can specify the font size using a keyword. Available keywords are: xx-small, x-small, small, medium, large, x-large, xx-large, larger, and smaller.

Available Units

UnitDescription
pxSpecifies the size in pixels.
ptSpecifies the size in points. According to the CSS2 specification, 1pt equals 1/72 of an inch, but the actual size varies by OS and display, so it is generally best to avoid using this unit.
%Specifies the size as a percentage. The reference value is the parent element's font size. When supporting IE8 or earlier, using % is the safest choice.
emSpecifies the size as a relative value where 1 equals the parent element's font size.
remSpecifies the size as a relative value where 1 equals the html element's (root element's) font size. This unit was introduced in CSS3.

Available Keywords

KeywordDescription
xx-smallEquivalent to 60% font size per the CSS2.1 specification.
x-smallEquivalent to 75% font size per the CSS2.1 specification.
smallEquivalent to 88.8% font size per the CSS2.1 specification.
mediumEquivalent to 100% font size per the CSS2.1 specification.
largeEquivalent to 120% font size per the CSS2.1 specification.
x-largeEquivalent to 150% font size per the CSS2.1 specification.
xx-largeEquivalent to 200% font size per the CSS2.1 specification.
largerOne step larger than the inherited keyword size. For example, if the parent element's font size is medium, this is interpreted as large.
smallerOne step smaller than the inherited keyword size. For example, if the parent element's font size is medium, this is interpreted as small.

Browser Preview

<p style="font-size: 12px;">This is a p element. font-size is set to 12px.</p>

<p style="font-size: 1.2rem;">This is a p element. font-size is set to 1.2rem.</p>

<p style="font-size: large;">This is a p element. font-size is set to large.</p>

Browser Compatibility

Chrome Chrome
1+
Firefox Firefox
1+
Safari Safari
1+
Edge Edge
12+
Supported in all versions
IE IE
11
10
9
8
7
6
Opera Opera
7+
6 or earlier ×
iOS Safari iOS Safari
1+
Android Android Browser
4.4+
3 or earlier ×
Chrome Android Chrome Android
Latest
Same support as desktop version
Firefox Android Firefox Android
Latest
Same support as desktop version

※ Version data based on MDN.

Overview

You can specify the font size.

The most commonly used unit in modern web development is px. The pt unit is best avoided because its rendered size varies depending on the OS and display.

In IE8 and earlier, there are known bugs: text with font-size set in px does not scale when the browser zoom is changed, and when using em, inheritance from parent elements does not work correctly. Therefore, when supporting IE8 or earlier, it is safest to specify font-size using %.

When using em, note that the reference size is the parent element's font size. For example, if a div element has 12px, a child p element has 2.0em, and a grandchild span element also has 2.0em, then the span's font size will be 48px.

div { font-size: 12px;} /* font-size is 12px */
div > p { font-size: 2.0em;} /* parent div is 12px, so font-size is 24px */
div > p > span { font-size: 2.0em;} /* parent p is 24px, so font-size is 48px */

Using the rem unit, you can specify the size relative to the html element's (root element's) font size. Unlike em, it is unaffected by the parent element's font size — the reference is always constant, making it very convenient. However, since it was introduced in CSS3, it does not work in older browsers.

html { font-size: 16px;}
div { font-size: 2.0rem;} /* html element is 16px, so font-size is 32px */
div > p { font-size: 2.0rem;} /* html element is 16px, so font-size is 32px. Unaffected by parent div. */

Keyword values are available but are rarely used in practice, as the rendered size varies by browser and fine-grained adjustment is not possible.

In modern web development, the base font size is typically set between 15px and 18px.

Note that almost all browsers enforce a minimum font size, and any font size specified below that threshold will be rendered at the minimum font size instead.

If you find any errors or copyright issues, please .