Overflow, Outline & Display

Three properties that control how a box relates to its content and its neighbors: what spills out, what draws outside without shifting layout, and what box type the element becomes.

CSS6 min readConcept 8 of 43

Three properties, three different jobs

overflow decides what happens when content is bigger than its container. The default is visible, meaning the content spills out and is not clipped. hidden clips it, scroll always shows a scrollbar, and auto shows one only when needed.

outline draws a line OUTSIDE the border edge. Unlike border, an outline is not part of the box model: it takes up no space and never shifts neighboring elements. That is why it is the right property for focus rings, which must highlight an element without reflowing the page.

display sets the box type the element generates: block, inline, inline-block, flex, grid, none, or contents. It is the most fundamental layout property, because it determines whether an element starts on its own line, flows with text, or disappears entirely.

Each one fixes a layout problem nothing else can

Without overflow, long content would always break your layout. A table too wide for its column, a code block longer than its container, or a chat transcript that should scroll independently all need overflow: auto or hidden to behave. The property is what makes bounded UI regions possible.

outline exists because focus indicators must be visible WITHOUT moving content. If a focus ring used border, focusing a button would push its neighbors by the border width. Outline draws over the surrounding area and leaves layout untouched, which is why the accessibility guidelines and the default :focus-visible style both use it.

display: none is the only way to fully remove an element from layout and the accessibility tree. visibility: hidden keeps the space reserved. Knowing the difference is the difference between a tab panel that collapses cleanly and one that leaves a gap.

The values that matter day to day

**Overflow values:** visible (spill out), hidden (clip, no scrollbar, still scrollable via JS), scroll (always show scrollbar), auto (scrollbar only when needed), and clip (clip, NOT scrollable even via JS). Use longhands overflow-x and overflow-y when the axes differ, for example a horizontal-only scroller: overflow-x: auto; overflow-y: hidden;.

**Text truncation** needs three properties together: overflow: hidden, white-space: nowrap, and text-overflow: ellipsis. Miss any one and it breaks: without nowrap the text wraps instead of truncating, without overflow: hidden the overflow still shows.

**Outline vs border:** border is in the box model and takes up layout space; outline is outside the box model and takes up none. Use outline-offset to push the outline away from the border edge, which is how you get a focus ring with a visible gap. Outline cannot be styled per side the way border can.

**Display values:** block fills width and starts a new line. inline flows with text and ignores width, height, and vertical margin. inline-block flows inline but respects width and height. none removes the box completely. contents dissolves the element's own box so its children join the grandparent's layout directly.

**none vs visibility: hidden:** display: none removes the element from layout and the accessibility tree, so it takes up no space and screen readers skip it. visibility: hidden keeps the box's space reserved but invisible, and is inherited, so a child can override it with visibility: visible. Pick none when the element should truly disappear; pick hidden when you need to preserve layout space.

Try it

See the four overflow values side by side on the same overflowing content, then compare outline vs border to watch outline draw without shifting layout.

Overflow values

/* four values, same tall content */
.box {
  height: 72px;
  overflow: visible /* default */
   hidden /* clip */
   scroll /* always */
   auto /* if needed */
}

Four overflow values

visiblespills out

Line one of the content.

Line two keeps growing.

Line three overflows.

Line four is past the box.

hiddenclipped

Line one of the content.

Line two keeps growing.

Line three overflows.

Line four is past the box.

scrollalways bar

Line one of the content.

Line two keeps growing.

Line three overflows.

Line four is past the box.

autoif needed

Line one of the content.

Line two keeps growing.

Line three overflows.

Line four is past the box.

Each box is 72px tall holding four lines. `visible` spills, `hidden` clips, `scroll` always shows the bar, `auto` shows it only when needed.

outline vs border

/* border: takes up space */
.a { border: 4px solid red; }
 
/* outline: no space taken */
.b { outline: 4px solid red; }
 
/* outline-offset adds a gap */
.c { outline: 4px solid red;
  outline-offset: 4px; }

border vs outline

border: 4px solid red
beforeboxafter

The box grew by 4px and pushed "after" to the right.

outline: 4px solid red
beforeboxafter

Nothing shifted: outline draws over neighbors, no space taken.

outline + outline-offset: 4px
beforeboxafter

A 4px gap between the outline and the box edge. Layout still untouched.

Text truncation

/* needs all three */
.truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  max-width: 120px;
}

Three-property truncation

all three present
The quick brown fox jumps over the lazy dog

Cuts at 120px and adds the ellipsis. Correct.

missing white-space: nowrap
The quick brown fox jumps over the lazy dog

Text wraps instead of truncating. No ellipsis appears.

missing overflow: hidden
The quick brown fox jumps over the lazy dog

Text overflows visibly past the 120px cap. No clipping.

Drop any one of the three and truncation breaks. `white-space: nowrap` stops wrapping, `overflow: hidden` clips, `text-overflow: ellipsis` paints the dots.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1You want a box that clips its overflowing content but does NOT show a scrollbar and can NOT be scrolled programmatically via scrollTop. Which value do you use?
  2. 2You add `outline: 3px solid red` to a button. What happens to the layout of the button and its neighbors?
  3. 3An element is set to `display: none`. Which statement is TRUE?

Remember this

  • overflow: auto shows a scrollbar only when needed; hidden clips but stays scrollable via JS; clip clips and is not scrollable at all.
  • Text truncation needs all three: overflow: hidden + white-space: nowrap + text-overflow: ellipsis.
  • outline draws outside the box model and never shifts layout; use it for focus rings. border is in the box model and takes up space.
  • display: none removes the element from layout AND the accessibility tree. visibility: hidden keeps the space. display: contents dissolves the wrapper so children join the parent's layout.

Done with this concept?

Mark it complete to track your progress. No login needed.