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
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:
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'.
A length value allows you to specify an absolute font size, regardless of the surrounding elements. There are eight possible values.
- em (the 'font-size' of the relevant font)
- ex (the 'x-height' of the relevant font)
- px (pixels, relative to the viewing device)
- 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
Examples of Absolute Values
Percentage values specify an absolute font size relative to the parent element's font size.
More Font Properties
Here are more CSS font properties you can use on your text: