CSS sizing and overflow

Quick reference for CSS width, height, min/max sizes, percentage heights and the containing block, and overflow including clip versus hidden.

リファレンスページの本文は現在英語です。

This page is about specified width and height, their min and max limits, percentage resolution, and overflow. It does not repeat box-sizing arithmetic or margin collapse (see the box-model page), the flex item min-width: auto floor (see Flexbox), or minmax(0, 1fr) track sizing (see Grid). When a flex or grid item overflows, start with those pages, then return here for overflow and percentage height.

A percentage height, such as height: 100%, only resolves when the containing block’s height is definite. If the containing block’s height is auto, the percentage is typically treated as auto and the child shrinks to its content instead of filling the parent. Percentage width more often resolves, because the containing block’s width is usually definite in normal flow.

overflow: hidden and overflow: clip both hide overflowing paint, but they are not the same. hidden can still establish a scroll container (programmatic scrolling, and it may become a sticky scrollport, as the position page notes). clip does not allow scrolling; overflow-clip-margin can extend the clip edge. clip is newer and should be treated as a compatibility-sensitive value.

Examples were parsed for syntax and structure. Used heights, scrolling, and clipping were not measured in a browser.

Official sources: MDN and the CSS specification. Fragments were checked with PostCSS 8 for syntax and structure. That is not a CSS conformance suite, and this is not a browser render or visual test.

CSS reference catalog → · CSS tutorial overview →

Width, height, min/max, and percentage containing blocks

min-width and min-height set a lower bound; max-width and max-height set an upper bound. They apply even when width or height is auto. A used size is clamped after the rest of the sizing rules, including box-sizing (see the box-model page).

For in-flow block boxes, height: 100% looks at the parent’s specified height, not at “however tall the parent ended up after its content.” A chain of auto heights, including an auto body, will not make 100% fill the viewport unless you also give the ancestors a definite height (for example on html and body).

Syntax or propertyInitial / defaultInheritedApplies toNotes
widthautonoall elements except non-replaced inlines in the usual wayCommon values: auto, a length, a percentage of the containing block width, min-content, max-content, fit-content. Percentages usually resolve because the containing block width is often definite. box-sizing changes what the length includes; that arithmetic stays on the box-model page.
heightautonoall elements except non-replaced inlines in the usual wayCommon values: auto, a length, or a percentage of the containing block height when that height is definite. If the containing block height is auto, a percentage height is typically treated as auto.
min-widthautonosame as widthCommon values: 0, a length, a percentage, auto. auto on flex and grid items is a content-based minimum and can block shrinking; see the Flexbox and Grid pages rather than repeating that rule here. 0 is the usual override when you want the item to shrink.
max-widthnonenosame as widthCommon values: none, a length, a percentage, or min-content / max-content. Useful caps such as 40rem on a text column. It does not by itself add wrapping or ellipsis; combine it with the text page when you need truncation.
min-heightautonosame as heightThe height-axis counterpart of min-width, including the automatic minimum on column flex items.
max-heightnonenosame as heightAn upper bound on height. Combined with overflow, it can create a constrained box that clips or scrolls.

Percentage height needs a definite containing block

.outer { height: 8rem; }
.inner { height: 100%; }
.auto { height: auto; }
.auto .inner { height: 100%; }

height: 100% can fill an 8rem parent. The same 100% inside a height: auto parent does not have a definite containing-block height to resolve against.

  • This is a specified-value rule, not a measured pixel height from a browser. Flex and Grid stretching are not used here so the percentage rule stays visible.
html
<div class="outer">
  <div class="inner">100% of an 8rem parent</div>
</div>
<div class="auto">
  <div class="inner">100% of an auto-height parent</div>
</div>
<style>
.outer, .auto { width: 16rem; font-family: sans-serif; border: 1px solid #0B5853; }
.outer { height: 8rem; }
.auto { height: auto; }
.inner { height: 100%; background: #F3EFE4; }
</style>

What this markup means

The first inner box is 100% of a parent with a definite 8rem height, so the percentage can resolve. The second parent has height: auto, so the child’s height: 100% has no definite containing-block height and is treated as auto, shrinking to the content rather than stretching the auto parent. This example does not set display: flex or grid, which have their own stretching rules on the Flexbox and Grid pages.

Related: Box model, Flexbox, Grid

MDN documentation → · CSS specification →

overflow: clip versus hidden

The initial overflow is visible. hidden, auto, and scroll all hide or provide a way to reach overflowing content, and they can establish a scroll container. That is why overflow: hidden on an ancestor can trap position: sticky, as already noted on the position page, and why a script can still adjust scrollTop on a hidden box in many engines.

overflow: clip is meant to clip without creating a scroll container. You should not expect to scroll a clip box, and it is a poorer choice when you wanted a sticky ancestor to be a scrollport. overflow-clip-margin can extend how far ink is kept. Support for clip is newer than hidden; treat it as a compatibility-sensitive value and keep hidden when you need a broadly available clip-and-scroll container.

Syntax or propertyInitial / defaultInheritedApplies toNotes
overflowvisiblenoblock containers, flex and grid containers, and some other boxesShorthand for overflow-x and overflow-y. Common values: visible, hidden, clip, auto, scroll. visible does not clip. auto shows scrollbars when needed. scroll reserves a scrollbar gutter in many engines. Setting one axis to something other than visible can affect the other; check both axes when results look surprising.
overflow: hiddenn/a (value)nosame as overflowClips overflowing paint and can still be a scroll container. Programmatic scrolling and sticky containment may still apply. It is not a synonym for clip, and it is not display: none.
overflow: clipn/a (value)nosame as overflowClips overflowing paint without creating a scroll container. Newer than hidden. overflow-clip-margin can adjust the clip edge. Do not document it as “the same as hidden, but newer.”

hidden and clip as distinct overflow values

overflow: hidden;
overflow: clip;

Both boxes clip a taller child, but only hidden is written as a potential scroll container. clip is the non-scrolling clip.

  • No scroll position is set in the example. Sticky is not used here; see the position page for overflow and sticky containing blocks.
html
<div class="hidden">
  <p>Clipped with hidden, still a possible scroll container.</p>
</div>
<div class="clip">
  <p>Clipped with clip, not intended as a scroll container.</p>
</div>
<style>
.hidden, .clip { width: 16rem; height: 3rem; font-family: sans-serif; border: 1px solid #0B5853; }
.hidden { overflow: hidden; }
.clip { overflow: clip; }
p { margin: 0; height: 6rem; }
</style>

What this markup means

Both parents have a 3rem height and a taller child, so the overflowing text is clipped. .hidden uses overflow: hidden, which may still establish a scroll container. .clip uses overflow: clip, which is the non-scrolling clip. The two values are written side by side so they are not documented as aliases.

Related: Position (sticky and overflow), Text (ellipsis conditions), Box model

MDN documentation → · CSS specification →