Codectionary / Developer documentation / CSS

overflow Property

overflow controls what happens when content is too large to fit its container. visible (default) lets content spill out. hidden clips anything beyond the box. scroll always shows scrollbars. auto adds scrollbars only when needed. overflow-x and overflow-y control each axis independently.

Syntax

overflow: visible | hidden | scroll | auto;

Examples

Basic Overflow Values

The four core values and their visual effect.

.visible { overflow: visible; } /* content spills out, default */
.hidden { overflow: hidden; height: 100px; } /* content beyond 100px is clipped */
.scroll { overflow: scroll; height: 100px; } /* always shows scrollbars */
.auto { overflow: auto; height: 100px; } /* scrollbars only appear if needed */

Truncating Text with Ellipsis

A common combination for single-line text truncation.

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
/* "This is a very long heading..." */

Parameters and values

  • visible (keyword): Default - overflowing content is not clipped
  • hidden (keyword): Overflowing content is clipped and inaccessible
  • scroll (keyword): Always shows scrollbars, even if content fits
  • auto (keyword): Shows scrollbars only when content overflows

Best practices

  • Use overflow: auto over overflow: scroll in most cases, so scrollbars only appear when actually needed
  • Setting overflow: hidden on a parent is a classic (if slightly dated) way to contain floated children - modern layouts typically use flexbox/grid instead
  • Combine overflow: hidden with text-overflow: ellipsis and white-space: nowrap for single-line text truncation
  • Remember overflow: hidden clips focusable content too - test keyboard navigation around clipped areas

At a glance

Purpose
Presentation and layout
File extension
.css
Runs in
Web browsers
Usually used with
HTML and JavaScript

Specifications & further reading

Related CSS documentation