Absolute Length Units
Example
html {
font-size: 16px;
}html {
font-size: 100%;
}'100%' keeps the user's default font size, while '16px' ignores the browser text size setting.
Common mistakes
- Expecting '1cm' to measure one real centimeter on a screen.
- Setting
html { font-size: 16px }, which overrides the user's chosen text size.
Key points
- Root and body font sizes use
remor '%', not 'px', so text follows the user's default font size. - Physical units like 'cm', 'mm' and 'pt' appear only in print styles, not in screen layouts.
- Borders, shadows and hairlines use 'px', where a fixed size is intended.
Interview questions
How many pixels is 1in in CSS?
Exactly '96px'. CSS fixes '1in' to '96px', so '1cm' is about '37.8px' and '1pt' is '1/72in'.
Is px an absolute unit in CSS?
Yes. A CSS pixel is a fixed reference unit, but on high-density screens one CSS pixel covers several device pixels.
When should I use pt in CSS?
Use 'pt' mostly in print style sheets, where font sizes in points match what printed documents expect.