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:

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:

CodeResult

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'.

CodeResult

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:

Absolute Values:

Examples of Relative Values

CodeResult

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

CodeResult

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.

CodeResult

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:

Enjoy this page?

  1. Link to this page (copy/paste into your own website or blog):
  2. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!

Sponsored Link: Design CODE-FREE Websites

Check a Domain:

ZappyHost Logo
Webydo Banner Ad