🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Expert Masterclasses.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

CSS Font Size

Master text sizing. Learn the power of pixels, rems, and fluid typography.

style.css
/* Responsive Type */
html {
font-size: 100%;
}
p {
font-size: 1.25rem;
}
Aa
styles.css
1 / 9
Aa

Tutor:The font-size property sets the size of the font. We can use absolute units like pixels (px) or relative units like rem and em.


Typography Mastery

Unlock nodes by learning units and scaling.

Absolute Units: Pixels

Pixels (px) are fixed-size units. They are precise but not responsive to user settings. A 16px font stays 16px even if the user requests larger text.

System Check

Why might pixels be bad for accessibility?


Typography Systems Hub

Share Type Scales

Designed a perfect fluid typography system? Share your calc() formulas.

Enjoying this guide?

Codesyllabus is 100% free and open-source. Support our mission, pay for server infrastructure, and fuel new tutorials by buying us a coffee!

CSS Font Size

Author

Pascual Vila

Frontend Instructor.

The font-size property sets the size of the text. Managing font size is crucial for readability, accessibility, and responsive design. CSS offers several units to control size, including pixels, ems, rems, and viewport units.

Absolute Units (px)

Pixels (px) are absolute units. A font size of 16px will always be 16 pixels high, regardless of the screen size or user preferences. While this offers precision for layout, it can be problematic for accessibility if users have set their browser to a larger default text size.

Relative Units (rem & em)

REM (Root EM): This unit is relative to the root element (usually <html>). If the root size is 16px, 1rem equals 16px, and 2rem equals 32px. This is the preferred method for responsive typography because it respects user browser settings.

EM: This unit is relative to the font size of the parent element. This allows for cascading size changes, but can lead to "compounding" issues where nested elements grow uncontrollably large.

Viewport Units (vw)

Viewport width (vw) units allow text to scale based on the width of the browser window. 5vw means the font size is 5% of the viewport width. This is excellent for large headlines that need to fit specific containers on any screen.

Typography Glossary

px (Pixel)
An absolute unit of measurement. 1px represents one dot on the screen (historically), though modern high-density screens map this differently.
rem (Root EM)
A relative unit based on the font-size of the root <html> element. Best for accessibility.
em
A relative unit based on the font-size of the parent element. Good for components that need to scale internally.
vw (Viewport Width)
A unit equal to 1% of the width of the viewport (browser window). 100vw is full width.
Root Element
The top-level element of the document, the <html> tag. Its default font-size is usually 16px.