Font-size property

Last updated: 2026-09-13

font-size Font-size property

The font-size CSS property sets the size of the text. It accepts absolute keywords, fixed lengths, or relative units such as em and rem, and is one of the most frequently used text styling properties.

Category
Initial Valuemedium
InheritedYes
Applies Toall
Animation Typefont-weight
CSS VersionCSS1
StatusStandard

📝 Syntax

font-size: xx-small | x-small | small | medium | large | x-large | xx-large | larger | smaller | <length> | <percentage>;

⚙️ Values

ValueTypeDescription
xx-small | x-small | small | medium | large | x-large | xx-large | larger | smallerKeywordAbsolute size keywords
<length>TypeA fixed font size, e.g. 16px
<percentage>TypeA percentage relative to the parent element's font size

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
font-size v1 v12 v1 v1 v1
Supported in all major browsers
Tip: Prefer relative units (em/rem) for font size so text scales with user settings and responsive layouts.
Warning: Avoid absolute keywords like xx-small or x-small; they render inconsistently across browsers.

❓ FAQ

QWhat is the difference between the px, em, and rem units in CSS?
Apx is a fixed pixel value that does not change with context; em is relative to the parent element's font size and compounds with nesting; rem is relative to the root element (html) and is unaffected by nesting. Use rem or clamp() for responsive layouts, em when you want scaling relative to a parent, and px for values like borders that should not scale with the font.
QWhat is the default font size that browsers use for web pages?
AThe default value is medium, which most browsers render as 16px. Setting html { font-size: 62.5% } makes 1rem equal to 10px, which simplifies calculations in multiples of ten, but note that it affects every element that uses rem, so use it with care.
QHow is a percentage value for font-size calculated relative to the parent?
AA percentage is resolved against the parent element's font-size: if the parent is 16px, font-size: 150% equals 24px. It scales proportionally with the parent, behaving like em, and suits emphasized text or lists that need to scale with their context.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏