English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive List of CSS Properties

CSS font-Usage and examples of size attribute

font-The size CSS property is used to set the font size of the element's text content.

The following table provides usage instructions and version history of this attribute, as well as its syntax in JavaScript scripts.

Default value:medium
Applies to:All elements
Inheritance:Yes
Animatable:Yes.Please refer to Animation properties.
Version:CSS 1,2,3
JavaScript syntax:JavaScript syntax: object.style.fontSize="medium"

font-Syntax of size usage

The syntax of this attribute is as follows:

font-size: xx-small | x-small | small | medium | large | x-large | xx-large | smaller | larger | length | percentage  | initial | inherit

The following example demonstrates how to use font-size attribute.

  body {
   font-size: 14px;
  }
  h1 {
   font-size: 2em;  
  }
Test see‹/›

Attribute value

The following table describes the value of this attribute.

ValueDescription
xx-small

A set of absolute size keywords. These keywords are scaled to the text font size based on the user's browser font setting preferences and the browser's internal font scaling algorithm.

The font-The median value of the size attribute (16px) matches the default font size of the user's browser.

x-small
small
medium
large
x-large
xx-large
smaller

Less than or greater than or greater than the font size of the parent element, used to separate the proportion of the above absolute size keywords.

For example, if the font size of the parent element is medium, the value of larger will make the font size of the current element large.

larger
lengthUse length units such as px, pt, cm, em, etc., and negative values are not allowed.
percentageSet the font size to a percentage of the font size of the parent element. Negative values are not allowed.
initialSet this attribute to its default value.
inheritIf specified, the associated element adopts the font of its parent element font-size attribute values.

Note:font-The default value of the size attribute in all modern browsers (such as Firefox, Chrome, IE, Safari, Opera, etc.) is medium (16px).

Browser compatibility

font-Browser compatibility of the size attribute, the numbers in the following table represent the minimum version number of the browser that supports this attribute; all mainstream browsers support this attribute.

  • Firefox 1+

  • Google Chrome1+

  • Internet Explorer 4+

  • Apple Safari 1+

  • Opera 4+

Further reading

Please refer to the following tutorials:CSS font,CSS text.

Related properties and rules:line-height,font,font-family,font-style,font-variant,font-weight,@font-face.