The font-size property sets how large text appears. It is essential for readable body copy, clear headings, and a visual hierarchy across your site.
01
px
Fixed pixels.
02
rem
Root relative.
03
em
Parent relative.
04
Keywords
small, large.
05
Hierarchy
Headings vs body.
06
Responsive
clamp(), vw.
Fundamentals
Introduction
The font-size property in CSS is used to set the size of the font for an element's text content. It is a crucial property for controlling the visual appearance and readability of text on web pages.
Definition and Usage
By adjusting the font size, you can create a hierarchy of text elements, making your content more accessible and visually appealing. Set a comfortable base size on body or html, then scale headings and UI labels relative to that base.
💡
Beginner Tip
Many sites use html { font-size: 100%; } (16px default) and body { font-size: 1rem; } for body text. Headings might use 1.5rem, 2rem, or larger.
Foundation
📝 Syntax
The syntax for the font-size property is simple. You can specify the font size using various units:
syntax.css
element{font-size:value;}
Here, value can be specified in different units such as pixels (px), em, rem, percentages (%), points (pt), and others.
clamp() picks the middle value when it falls between the minimum (1.75rem) and maximum (3rem), giving fluid but bounded typography.
A11y
♿ Accessibility
Use at least 16px (1rem) for body text on most sites for comfortable reading.
Prefer rem or % so users who change browser default font size still get readable text.
Maintain size contrast between headings and body without making headings excessively large on mobile.
Test zoom up to 200% to ensure text remains readable and layouts do not break.
Do not disable user scaling in the viewport meta tag.
🧠 How font-size Works
1
You set a size value
Choose px, rem, em, %, keywords, or a function like clamp().
Declaration
2
Browser computes size
Relative units are converted to an absolute pixel size for rendering based on root or parent values.
Computed value
3
Text renders at that size
Glyphs scale accordingly. Inherited children use the computed size unless overridden.
Rendering
=
🔢
Clear visual hierarchy
Headings, body copy, and labels each appear at an appropriate readable size.
Compatibility
🖥 Browser Compatibility
The font-size property is supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. It is one of the fundamental CSS properties with wide-ranging support across platforms and devices.
✓ Baseline · Universal support
font-size everywhere
All units and keywords work in every browser, including legacy environments.
99%Universal support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions
Full support
OperaAll modern versions
Full support
font-size property99% supported
Bottom line:font-size is universal. Choose units thoughtfully for accessibility and responsive design.
Wrap Up
🎉 Conclusion
The font-size property is essential for web developers to control the size of text on their websites. By using this property, you can enhance the readability and visual hierarchy of your content, making it more accessible and engaging for users.
Experiment with different units and values to find the right balance for your design. For most projects, start with rem-based body text and scale headings from there.
Forget that em compounds in deeply nested elements
Disable user font scaling in the viewport meta tag
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about font-size
Use these points when sizing text on your site.
5
Core concepts
Aa01
Text size
Core typography.
Purpose
medium02
Default 16px
medium keyword.
Default
rem03
Prefer rem
Root relative.
Best practice
📈04
Hierarchy
Headings vs body.
Layout
🔁05
Inherited
Children inherit.
Cascade
❓ Frequently Asked Questions
The font-size property sets the size of text for an element. It controls how large or small characters appear on the page.
The initial value is medium, which browsers typically render as 16px for normal body text.
rem is often preferred for body text because it scales with the root font size and respects user browser settings. px gives fixed pixel control and is still common for small UI details.
em is relative to the font size of the element or its parent. rem is relative to the root html element font size, so it is more predictable for site-wide typography.
Yes. Units like vw and vh size text relative to the viewport. clamp() is a popular way to combine viewport scaling with minimum and maximum limits.