In CSS, font size can be specified using several different units of measurement. Here are some of the most commonly used units:
px
: Pixels are a fixed-size unit of measurement that are the same size on all screens. They are commonly used for precise control of text size.em
: An em is a relative unit of measurement that is equal to the font size of the element. For example, if the font size of a paragraph is 16px, then 1em is also equal to 16px.rem
: A rem is also a relative unit of measurement, but it is based on the font size of the root element (usually the<html>
element). This makes it useful for creating responsive designs that scale with the screen size.%
: A percentage is also a relative unit of measurement that is based on the font size of the parent element. For example, if the font size of a parent element is 16px, then 100% is equal to 16px.
Here’s an example of how to use the font-size
property in CSS:
h1 {
font-size: 32px;
}
p {
font-size: 1.2em;
}
In this example, the font size of the <h1>
element is set to 32 pixels, while the font size of the <p>
element is set to 1.2 times the font size of the parent element.