HTML Font Size Code
In HTML, font size is specified using CSS (Cascading Style Sheets). Font size is specified using the font-size property.
The actual value of the font-size property can be specified in different ways. You can specify font size in any of the following ways:
- Absolute Size
- Relative Size
- Fixed Size
- Percentage
This page includes examples of these different methods.
You can use the following HTML code to specify font size within your HTML documents. All you need to do is select your preferred option, then change the values to suit.
Option 1: Absolute Size
Absolute size refers to an entry in a table of font sizes that is calculated, and kept by the browser (or other user agent). Because of this, the text will always be displayed at the same size regardless of its surrounding elements. This is because the sizes are pre-calculated by the browser/user agent.
Here's an example of setting font size using absolute sizes:
| Code | Result |
|---|---|
|
|
Absolute size - xx-small Absolute size - x-small Absolute size - small Absolute size - medium Absolute size - large Absolute size - x-large Absolute size - xx-large |
Option 2: Relative Size
Relative size allows you to set the font size relative to the parent element. This means that different text with the same (relative) value could actually appear in many different sizes - even on the same page. It all depends on the text's parent element. There are two possible values: 'smaller' and 'larger'.
| Code | Result |
|---|---|
|
|
Font size specified using relative values - smaller Font size specified using relative values - larger |
Option 3: Length Value
A length value allows you to specify an absolute font size, regardless of the surrounding elements. There are eight possible values.
Relative Values:
- em (the 'font-size' of the relevant font)
- ex (the 'x-height' of the relevant font)
- px (pixels, relative to the viewing device)
Absolute Values:
- in (inches -- 1 inch is equal to 2.54 centimeters)
- cm (centimeters)
- mm (millimeters)
- pt (points -- the points used by CSS2 are equal to 1/72th of an inch)
- pc (picas -- 1 pica is equal to 12 points)
Examples of Relative Values
| Code | Result |
|---|---|
|
|
Font size specified at 1.2em Font size specified at 1.4em Font size specified at 1.8em Font size specified 2ex Font size specified at 3ex Font size specified at 4ex Font size specified at 12px Font size specified at 14px Font size specified at 18px |
Examples of Absolute Values
| Code | Result |
|---|---|
|
|
Font size specified at 0.12in Font size specified at 0.18in Font size specified at 0.25in Font size specified at 0.35cm Font size specified at 0.45cm Font size specified at 0.6cm Font size specified at 3.5mm Font size specified at 4.5mm Font size specified at 6mm Font size specified at 10pt Font size specified at 12pt Font size specified at 16pt Font size specified at 0.8pc Font size specified at 1pc Font size specified at 1.2pc |
Option 4: Percentage Values
Percentage values specify an absolute font size relative to the parent element's font size.
| Code | Result |
|---|---|
|
|
Smaller font size specified using percentage values - 90% Larger font size specified using percentage values - 150% |
More Font Properties
Here are more CSS font properties you can use on your text:
- font
- font-family
- font-size
- font-size-adjust
- font-stretch
- font-style
- font-variant
- font-weight
- letter-spacing
- line-height
- color
- background-color
- text-align
- text-decoration
- text-indent
- text-shadow
- text-transform

