column-wrap

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The column-wrap CSS property specifies the wrapping behavior of overflow columns in a CSS multi-column layout.

Syntax

css
/* Keywords */
column-wrap: auto;
column-wrap: nowrap;
column-wrap: wrap;

/* Global values */
column-wrap: inherit;
column-wrap: initial;
column-wrap: revert;
column-wrap: revert-layer;
column-wrap: unset;

Values

auto

The initial value. If the content container's column-height is set to a <length>, auto resolves to wrap, otherwise it resolves to nowrap.

nowrap

Columns overflow in the inline direction.

wrap

Overflow columns are placed in a new row in the block direction.

Description

The column-wrap property can be used to set the columns of a CSS multi-column layout to wrap onto a new row when they start to overflow the column width. This is useful for creating more readable layouts when using the column-count or column-width property to set multiple columns.

Without column-wrap, excess columns will overflow to the side, and readers will have to scroll in the inline direction to read all the content. The column-height property, along with column-wrap, allows you to set a specific height for the columns and wrap them onto a new row of columns when the container edge is reached.

The default value of column-wrap is auto, which resolves to wrap when column-height is set to a <length> value; wrap allows the fixed-height columns to wrap onto multiple rows. When column-height is equal to auto, column-wrap: auto resolves to nowrap, allowing the columns to overflow horizontally if a fixed container height is set.

As a result of this default behavior, generally you don't need to explicitly set the column-wrap property.

Formal definition

Initial valueauto
Applies tomulticol elements
Inheritedno
Computed valueas specified
Animation typediscrete

Formal syntax

column-wrap = 
auto |
nowrap |
wrap

Examples

Basic usage

This example demonstrates basic usage of the column-wrap property to create a wrapped multi-col layout via setting a column-height property.

HTML

We include a poem by Dr. Seuss using an <ol> containing 28 <li>s, followed by the author's name in a <p>.

html
<ol>
  <li>One fish</li>
  <li>Two fish</li>
  <li>Red fish</li>
  <li>Blue fish</li>
  ...
</ol>
<p>-- Dr. Seuss</p>

CSS

We define the <ol> to be a multi-column container by setting the column-width property to 150px, meaning the container will contain as many columns as possible with each being at least 150px wide. The gap property sets a horizontal gap between columns and a vertical gap between rows of columns. We then set the column-height to 3em, causing the column-wrap property's default auto value to resolve to wrap to create wrapped rows of columns.

css
ol {
  column-width: 150px;
  gap: 2em;
  column-height: 3em;
}

Result

Comparing wrap and nowrap

This example features a multi-column layout that demonstrates the difference between the wrap and nowrap values by allowing you to toggle the column container's column-wrap value between the two. The result is a layout that dynamically changes between horizontal and vertical scrolling.

HTML and JavaScript

The markup for this example contains multiple paragraphs of content, taken from MDN's HTML, CSS, and JavaScript home pages, and a JavaScript-powered <input type="checkbox"> element to toggle the container's column-wrap property value between nowrap and wrap. The HTML and JavaScript have been hidden for brevity.

CSS

We make the <body> element a multi-col container by setting the column-count to 3. We then set a gap of 3em 2em, resulting in a 3em gap between rows and a 2em gap between columns.

We then set a column-height of 90vh, making the columns nearly as tall as the viewport. We also set column-wrap to nowrap, causing excess content columns to overflow horizontally. This is required because the initial column-wrap value is auto, which resolves to wrap when column-height is set to a <length> value.

The checkbox toggles the column-wrap property between nowrap and wrap. When set to wrap, the excess content columns overflow vertically into new rows of columns, creating the vertical layout. The column-height value causes each row of columns to fill the viewport.

css
body {
  column-count: 3;
  gap: 3em 2em;
  padding: 0 2em;
  column-height: 90vh;
  column-wrap: nowrap;
}

Next, we set the <h1> element's column-span property to all, to make the heading span across all the columns, and set the margin-top property of the first <p> to 0 so that it lines up with the top of the columns.

css
h1 {
  column-span: all;
}

p:first-of-type {
  margin-top: 0;
}

Result

Toggle the checkbox to change the value of the column-wrap property and switch the layout between horizontal and vertical scrolling. When column-wrap is set to nowrap, the columns overflow horizontally; when column-wrap is set to wrap, new rows of columns are added vertically.

Specifications

Specification
CSS Multi-column Layout Module Level 2
# propdef-column-wrap

Browser compatibility

See also