CSS · Layout and visual systems
How do percentages and intrinsic sizing interact?
Short answer
Percentages resolve against the containing block's size, and padding and margin percentages resolve against its inline size. Intrinsic keywords such as min-content and max-content size boxes from their contents.
A percentage is not an absolute size. It depends on the containing block, and different properties use different axes. Width resolves against the containing block width. Height resolves against the containing block height, but only when that height is definite.
.wrap {
width: 60rem;
}
.half {
width: 50%;
padding: 5%;
}
.fill {
height: 100%;
}Why percentages fail
- A percentage height needs a parent with a definite height; auto does not provide one
- Percentage padding and margin on both axes resolve against the containing block's inline size
- Percentage widths can overflow when padding and border are added under content-box
- min-content is the smallest size without overflow; max-content is the size with no wrapping
- fit-content clamps between the available size and the content's preferred size
The height: 100% chain problem is a classic. If every ancestor has auto height, the percentage cannot resolve. Using flex or grid on the parent, or setting a definite height, fixes it more reliably than repeating height: 100% up the tree.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why does height: 100% sometimes do nothing?
- 2What does padding-top: 50% resolve against?
- 3What is the difference between min-content and max-content?
- 4How does fit-content size a box?
Say it in the interview
Percentages resolve against the containing block, but not always the axis you expect. Width uses the containing block's width, while padding and margin percentages on both axes also use the inline size. A percentage height needs a definite parent height, which is why height 100% chains fail. For content-driven sizing I use min-content, max-content or fit-content instead of guessing with percentages.
Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.
Related questions
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live CSS mock interview and get scored feedback on depth, clarity and confidence.