Percentages and reference sizes
Definition and purpose
A CSS percentage represents a fraction of a reference quantity determined by the property. For a normal block width it is typically the containing block width; for font-size it is the inherited font size. The percentage sign alone does not identify its basis.
Width and font-size use different bases
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> .parent { width: 240px; font-size: 20px; } #a { width: 50%; font-size: 150%; } </style> </head> <body> <div class="parent"> <div id="a">Text</div> </div> </body></html>Width uses 240px; font size uses 20px.
Syntax and mental model
In horizontal writing mode a normal block with a 240px containing block and width: 50% has a 120px content width in the default content-box model. Percentage padding on a normal block resolves against the containing block inline size, even for top padding. Percentage height needs an appropriate definite basis; otherwise it can behave as auto in normal flow. Later sizing lessons explain exceptions.
Padding uses the inline dimension
<!doctype html><html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>CSS practice</title> <style> .parent { width: 200px; height: 100px; } #a { width: 50%; padding-top: 10%; height: 50%; } </style> </head> <body> <div class="parent"> <div id="a">Text</div> </div> </body></html>Top padding uses 200px; height uses the explicit 100px height.
Common mistakes
Do not assume every percentage is relative to the viewport or to the element itself. Padding can increase total width; later box model lessons show how to control that. Avoid fixed heights that clip enlarged text.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Absolute and font-relative lengths. Next lesson: Viewport and container units overview.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Percentages and reference sizes — knowledge check
Five questions on percentages and reference sizes.
Containing width 300px, width 60%. Result?
Parent font 20px, font-size 125%. Result?
In ordinary horizontal flow, top percentage padding refers to what?
Why might height: 50% act like auto?
What determines the reference for a percentage?