Definite and indefinite sizes
Definition and purpose
A definite size can be established without performing the dependent layout. An indefinite size may require content measurement. Definite is not synonymous with pixels: a percentage resolved against a definite size can itself be definite.
Auto-height parent
<!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> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { line-height: 20px; width: 50%; height: 50%; background: #dbeafe; } #parent { width: 200px; background: #eee; } </style> </head> <body> <div id="parent"> <div id="a">Detail</div> </div> </body></html>Width resolves but height follows content.
Syntax and mental model
In normal flow, an ordinary non-positioned block with percentage height needs a suitable definite containing-block height. In the auto-height example, the child height behaves as auto and its single line is 20px tall. Set the parent height to 120px and the same child resolves to 60px. The width percentage resolves in both examples against the definite 200px width. Flex and Grid introduce additional definiteness rules, so do not generalize this block example to all layout modes.
Definite block size
<!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> body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { line-height: 20px; width: 50%; height: 50%; background: #dbeafe; } #parent { width: 200px; background: #eee; } #parent { height: 120px; } </style> </head> <body> <div id="parent"> <div id="a">Detail</div> </div> </body></html>Half of 120px is 60px.
Common mistakes
Adding min-height to an auto-height parent is not the same as supplying a definite height for a normal-flow percentage child. Inspect used geometry, not only the declared percentage.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Intrinsic and extrinsic sizing. Next lesson: Aspect ratio transfer and replaced sizing.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Definite and indefinite sizes — knowledge check
Five questions on definite and indefinite sizes.
Can a percentage be definite?
Child height 50% of definite 160px?
What happens in the auto-height block example?
Does width 50% resolve against parent width 200px here?
Which layout has additional definiteness rules?