CSS column-width Property

The column-width property sets the preferred width of columns in a CSS multi-column layout, allowing the browser to determine how many columns fit within the available space.

It accepts auto or a positive CSS length such as 200px, 15rem, or 20em. The specified width is a preferred measurement rather than a fixed column width.

The browser may adjust the actual column width to fill the container while respecting the available space, column gaps, and any specified column-count.

column-width Syntax

The column-width property accepts auto or a positive CSS length.

selector {
  column-width: 200px;
}

General Syntax

selector {
  column-width: auto | <length>;
}

Automatic Width

.article {
  column-width: auto;
}

Pixel Width

.article {
  column-width: 250px;
}

Relative Width

.article {
  column-width: 18rem;
}

Calculated Width

.article {
  column-width: clamp(200px, 25vw, 350px);
}

CSS-Wide Keywords

.article {
  column-width: inherit;
}
.article {
  column-width: initial;
}
.article {
  column-width: unset;
}
.article {
  column-width: revert;
}
.article {
  column-width: revert-layer;
}

Zero, negative lengths, and percentages are not valid column-width values.

Property Values

The property accepts the keyword auto or a positive length.

Value Description
auto The column width is determined by other layout constraints, including column-count. This is the initial value.
200px Requests columns approximately 200 CSS pixels wide.
15rem Requests a width relative to the root element's font size.
20em Requests a width relative to the element's font size.
250pt Requests a width using the CSS point unit.
calc(180px + 2rem) Uses a calculated positive length.
clamp(200px, 25vw, 350px) Uses a responsive preferred width with minimum and maximum limits.

CSS-Wide Keywords

Value Description
inherit Uses the computed value from the parent element.
initial Resets the property to auto.
unset Resets the property to auto because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Multi-column containers
Computed value auto or an absolute length
Animation type By computed value type; length values interpolate, while auto is discrete
Percentages Not accepted
Zero and negative values Not accepted
Layout effect Influences the used column width and number of columns

The specified length is a preferred column width. The browser calculates the actual width based on the available container space and the other multi-column properties.

How It Works

The browser uses the specified column-width as a target when determining the number and width of columns.

Step 1: Define a Container

.article {
  width: 900px;
}

Step 2: Specify a Preferred Column Width

.article {
  width: 900px;
  column-width: 250px;
}

Step 3: Add Column Spacing

.article {
  width: 900px;
  column-width: 250px;
  column-gap: 30px;
}

Step 4: Determine How Many Columns Fit

With a 900-pixel container, a preferred width of 250 pixels, and a 30-pixel gap, three columns can fit.

Step 5: Distribute Available Space

The browser distributes the available space between the three columns, giving each an actual width of 280 pixels.

Step 6: Flow Content Through the Columns

The content flows from one column to the next according to the multi-column layout and fragmentation rules.

Important Distinction

The browser does not create fixed 250-pixel columns in this example. It uses the requested width to determine a suitable column arrangement, then expands the columns to fill the available space.

auto

The auto value allows the browser to determine the column width from the other multi-column settings.

Basic Example

.article {
  column-width: auto;
}

Using column-count

.article {
  column-count: 3;
  column-width: auto;
}

The browser divides the available width into three columns, accounting for the column gaps.

Default Values

.article {
  column-count: auto;
  column-width: auto;
}

When both properties are auto, the element does not establish a multi-column layout solely from these declarations.

Resetting a Preferred Width

.article {
  column-width: 250px;
}
.article.single-layout {
  column-width: auto;
}

Resetting the width to auto removes the preferred width constraint. The resulting layout depends on the other column properties.

When to Use

Use auto when the desired number of columns is more important than their preferred width.

Length Values

Positive CSS length values establish the preferred width of each column.

Pixels

.article {
  column-width: 240px;
}

Pixels provide a predictable CSS measurement for the preferred column width.

rem Units

.article {
  column-width: 18rem;
}

The rem unit is relative to the root element's font size.

em Units

.article {
  column-width: 20em;
}

The em unit is relative to the element's font size and can be useful for text-oriented layouts.

Viewport Units

.article {
  column-width: 25vw;
}

Viewport units allow the preferred column width to vary with the viewport size.

Points

.article {
  column-width: 180pt;
}

Points are absolute CSS length units and may be useful in print-oriented styles.

Invalid Zero Width

.article {
  column-width: 0;
}

A zero column width is invalid because column-width requires a positive length.

Invalid Negative Width

.article {
  column-width: -200px;
}

Negative widths are invalid.

Invalid Percentage Width

.article {
  column-width: 30%;
}

Percentages are not accepted by column-width.

When to Use Length Values

Use a length when you want the browser to create as many columns as reasonably fit while keeping each column near a preferred reading width.

Preferred vs. Actual Width

The column-width property defines a preferred width, not a guaranteed exact measurement.

Preferred Width Example

.article {
  width: 900px;
  column-width: 250px;
  column-gap: 30px;
}

Column Count Calculation

The browser can fit three columns because three preferred widths and two gaps require 810 pixels.

/* Preferred widths and gaps:
   (3 * 250px) + (2 * 30px) = 810px */

Actual Width Calculation

The remaining available width is distributed across the columns.

/* Actual column width:
   (900px - 60px) / 3 = 280px */

Narrow Container

.article {
  width: 220px;
  column-width: 250px;
}

When the container is narrower than the preferred column width, the browser can use a single narrower column instead of forcing horizontal overflow solely to preserve the requested width.

Wider Container

.article {
  width: 1200px;
  column-width: 250px;
  column-gap: 30px;
}

A wider container may accommodate more columns, depending on the specified gap and any column-count constraint.

Practical Consideration

Use column-width when maintaining a comfortable approximate column width is more important than controlling the exact number of columns.

Interaction with column-count

The column-width and column-count properties work together to determine the column layout.

Width Only

.article {
  column-width: 250px;
}

The browser determines how many columns fit.

Count Only

.article {
  column-count: 3;
}

The browser creates the requested number of columns and calculates their width from the available space, subject to layout constraints.

Width and Count Together

.article {
  column-width: 250px;
  column-count: 3;
}

The browser uses both values. The count limits the number of columns, while the preferred width can cause fewer columns to be used when the container is too narrow.

Maximum Column Count

.article {
  column-width: 220px;
  column-count: 4;
}

The browser will not normally create more than four columns in a single column row from these settings. It may use fewer when space is limited.

Responsive Column Count

.article {
  column-width: 240px;
  column-count: auto;
}

The browser automatically determines the number of columns based on the available width.

Important Distinction

When both properties have non-auto values, column-count is not a guarantee that exactly that many columns will appear. The preferred width can limit the number that fit.

Interaction with column-gap

The column-gap property controls the spacing between adjacent columns and affects how many preferred-width columns can fit.

Basic Example

.article {
  column-width: 250px;
  column-gap: 30px;
}

Smaller Gap

.article {
  column-width: 250px;
  column-gap: 10px;
}

A smaller gap leaves more available space for columns and may allow additional columns to fit.

Larger Gap

.article {
  column-width: 250px;
  column-gap: 50px;
}

A larger gap consumes more space between columns and may reduce the number that fit.

Default Gap

.article {
  column-width: 250px;
  column-gap: normal;
}

In multi-column layout, normal generally corresponds to a gap of 1em.

Adding Column Rules

.article {
  column-width: 250px;
  column-gap: 30px;
  column-rule: 2px solid #cccccc;
}

The column rule is drawn in the gap without reserving additional layout space.

Practical Consideration

Choose a gap that visually separates columns while preserving sufficient width for readable text.

columns Shorthand

The columns shorthand sets column-width and column-count in one declaration.

Width Only

.article {
  columns: 250px;
}

This sets column-width to 250px and resets column-count to auto.

Count Only

.article {
  columns: 3;
}

This sets column-count to 3 and resets column-width to auto.

Width and Count

.article {
  columns: 250px 3;
}

Equivalent Longhand Declarations

.article {
  column-width: 250px;
  column-count: 3;
}

Changing Only the Width

.article {
  columns: 250px 3;
  column-width: 300px;
}

The later longhand declaration changes the preferred width without resetting the column count.

Shorthand Reset Behavior

.article {
  column-count: 4;
  columns: 220px;
}

The shorthand resets column-count to auto, replacing the earlier count of four.

When to Use the Longhand

Use column-width when you want to change the preferred column width without affecting an existing column-count declaration.

Column Filling and Balancing

The column-fill property controls how content is distributed among columns, while column-width influences their horizontal dimensions.

Balanced Columns

.article {
  column-width: 250px;
  column-fill: balance;
}

The balance value asks the browser to distribute content as evenly as possible among the columns.

Sequential Filling

.article {
  height: 350px;
  column-width: 250px;
  column-fill: auto;
}

With a definite height, auto generally fills columns sequentially rather than balancing their heights.

Width Does Not Control Height

The column-width property does not directly specify column height. Height depends on content, fragmentation, and other layout constraints.

Content Overflow

When content cannot fit within a constrained multi-column container, additional columns or overflow may occur according to the layout rules.

Practical Consideration

Use column-width for horizontal sizing and column-fill for content distribution. They solve different layout problems.

Spanning Elements

The column-span property allows eligible elements to extend across all columns in a multi-column container.

Basic Example

.article {
  column-width: 250px;
  column-gap: 30px;
}
.article h2 {
  column-span: all;
}

Example HTML

<div class="article">
  <h2>CSS Layout Methods</h2>
  <p>Normal flow is the default layout method.</p>
  <p>Flexbox arranges items along one main axis.</p>
  <p>Grid provides two-dimensional layout control.</p>
  <p>Multi-column layout flows content into columns.</p>
</div>

Spanning Behavior

The heading spans the full available width, while the paragraphs below it flow into columns determined by the preferred width.

Multiple Spanning Elements

Each spanning element divides the content into separate multi-column sections.

Practical Consideration

Use spanning elements for headings or notices that should occupy the full container width without changing the preferred width of the surrounding columns.

Calculated Widths

CSS math functions and custom properties can provide flexible preferred column widths.

Using calc()

.article {
  column-width: calc(200px + 2rem);
}

The calc() function combines compatible lengths into a calculated preferred width.

Using clamp()

.article {
  column-width: clamp(200px, 25vw, 350px);
}

The clamp() function keeps the preferred width between specified limits.

Using min()

.article {
  column-width: min(300px, 30vw);
}

Using max()

.article {
  column-width: max(200px, 20vw);
}

CSS Custom Property

:root {
  --preferred-column-width: 240px;
}
.article {
  column-width: var(--preferred-column-width);
}

Component-Specific Width

.article {
  --preferred-column-width: 18rem;
  column-width: var(--preferred-column-width);
}

Calculated Width Considerations

The resulting width must be valid for column-width. It must be positive and cannot resolve to a percentage-based width.

Math functions control the preferred width, but the browser still determines the actual column width during layout.

Responsive Layouts

The column-width property is particularly useful for responsive layouts because the browser can adjust the number of columns automatically.

Automatic Responsive Columns

.article {
  column-width: 240px;
  column-gap: 30px;
}

The browser creates as many columns as fit while keeping them near the preferred width.

Maximum Column Count

.article {
  column-width: 240px;
  column-count: 3;
}

The count limits the number of columns while allowing fewer columns on narrower screens.

Desktop Width

.article {
  column-width: 280px;
  column-gap: 30px;
}

Tablet Width

@media (max-width: 900px) {
  .article {
    column-width: 240px;
    column-gap: 24px;
  }
}

Mobile Layout

@media (max-width: 600px) {
  .article {
    column-width: auto;
    column-count: 1;
  }
}

Responsive Width with clamp()

.article {
  column-width: clamp(200px, 25vw, 320px);
  column-gap: 25px;
}

Practical Consideration

Use a preferred width that supports comfortable reading. Very narrow columns can cause excessive line breaks, while overly wide columns can make text difficult to follow.

Practical Uses

The column-width property is useful for flowing text and lists that should adapt to the available container width.

Documentation Content

.documentation {
  column-width: 260px;
  column-gap: 30px;
}

Reference Lists

.reference-list {
  column-width: 220px;
  column-gap: 25px;
}

Technical Glossaries

.glossary {
  column-width: 240px;
  column-gap: 30px;
}

Article Text

.article-content {
  column-width: 18rem;
  column-gap: 2rem;
}

Navigation Lists

.link-list {
  column-width: 180px;
  column-gap: 20px;
}

Print Layouts

@media print {
  .article {
    column-width: 180pt;
    column-gap: 18pt;
  }
}

Avoiding Split Items

.reference-list li {
  break-inside: avoid;
}

The break-inside property can help keep individual list items together within a column, subject to available space and fragmentation rules.

When Not to Use

Do not use column-width when individual items need precise row and column placement. CSS Grid or Flexbox is generally better suited for those layouts.

column-width Example

The following example compares three preferred column widths within similar multi-column containers.

The browser determines the actual number and width of columns based on the available space. Resize the browser window to see how the layouts adapt.

<div class="column-width-demo">
  <div class="width-example">
    <h3>150px Preferred Width</h3>
    <div class="width-columns width-150">
      <p>HTML defines the structure of web pages using elements such as headings, paragraphs, and links.</p>
      <p>CSS controls presentation, including colors, spacing, typography, and layout.</p>
      <p>Selectors identify elements, while declarations define the styles applied to them.</p>
      <p>Responsive design helps content adapt to different screen sizes.</p>
    </div>
  </div>
  <div class="width-example">
    <h3>220px Preferred Width</h3>
    <div class="width-columns width-220">
      <p>HTML defines the structure of web pages using elements such as headings, paragraphs, and links.</p>
      <p>CSS controls presentation, including colors, spacing, typography, and layout.</p>
      <p>Selectors identify elements, while declarations define the styles applied to them.</p>
      <p>Responsive design helps content adapt to different screen sizes.</p>
    </div>
  </div>
  <div class="width-example">
    <h3>300px Preferred Width</h3>
    <div class="width-columns width-300">
      <p>HTML defines the structure of web pages using elements such as headings, paragraphs, and links.</p>
      <p>CSS controls presentation, including colors, spacing, typography, and layout.</p>
      <p>Selectors identify elements, while declarations define the styles applied to them.</p>
      <p>Responsive design helps content adapt to different screen sizes.</p>
    </div>
  </div>
</div>
.column-width-demo {
  display: grid;
  gap: 20px;
}
.column-width-demo .width-example {
  padding: 15px;
  border: 1px solid #cccccc;
  background-color: #f8f9fa;
}
.column-width-demo h3 {
  margin: 0 0 12px;
  font-size: 1.125rem;
}
.column-width-demo .width-columns {
  column-gap: 25px;
  column-rule: 1px solid #cccccc;
}
.column-width-demo .width-columns p {
  margin: 0 0 12px;
}
.column-width-demo .width-150 {
  column-width: 150px;
}
.column-width-demo .width-220 {
  column-width: 220px;
}
.column-width-demo .width-300 {
  column-width: 300px;
}
@media (max-width: 600px) {
  .column-width-demo .width-columns {
    column-width: auto;
    column-count: 1;
  }
}
Browser Result

150px Preferred Width

HTML defines the structure of web pages using elements such as headings, paragraphs, and links.

CSS controls presentation, including colors, spacing, typography, and layout.

Selectors identify elements, while declarations define the styles applied to them.

Responsive design helps content adapt to different screen sizes.

220px Preferred Width

HTML defines the structure of web pages using elements such as headings, paragraphs, and links.

CSS controls presentation, including colors, spacing, typography, and layout.

Selectors identify elements, while declarations define the styles applied to them.

Responsive design helps content adapt to different screen sizes.

300px Preferred Width

HTML defines the structure of web pages using elements such as headings, paragraphs, and links.

CSS controls presentation, including colors, spacing, typography, and layout.

Selectors identify elements, while declarations define the styles applied to them.

Responsive design helps content adapt to different screen sizes.

The 150-pixel example can fit more columns within the same available width because each column has a smaller preferred size.

The 220-pixel example requests wider columns, which may reduce the number that fit.

The 300-pixel example requests the widest columns and may display fewer columns, depending on the container width.

All three examples use the same column gap and rule style. Only the preferred column-width changes.

On narrow screens, the media query switches the content to a single-column layout for improved readability.

Accessibility

Appropriate column widths can improve readability, but multi-column layouts should be tested carefully across different screen sizes and zoom levels.

Maintain Readable Line Lengths

Choose a preferred width that avoids excessively short or long lines of text.

Consider Browser Zoom

At increased zoom levels, fewer columns may fit. Test layouts to ensure content remains readable without unnecessary horizontal scrolling.

Preserve Source Order

Multi-column layout changes visual presentation without changing the document's source order. Assistive technologies generally follow the HTML structure.

Avoid Excessive Column Counts

Too many narrow columns can make content difficult to follow, particularly for readers using magnification.

Provide Adequate Column Spacing

Use sufficient column-gap to distinguish adjacent columns without wasting available reading space.

Responsive Layouts

Allow the number of columns to decrease on smaller screens. A single column is often preferable for narrow viewports.

Avoid Fixed Heights for Long Text

Fixed-height multi-column containers can create horizontal overflow when content requires additional columns. Allow content to grow naturally when possible.

Test Real Content

Check layouts with realistic headings, paragraphs, links, and lists to ensure the preferred width works for the intended content.

Important Considerations

Keep the following points in mind when using column-width:

  • Purpose: Sets the preferred width of columns in a CSS multi-column layout.
  • Initial value: auto.
  • Inheritance: The property is not inherited.
  • Valid values: auto or a positive CSS length.
  • Length units: Supports units such as px, rem, em, and vw.
  • Percentages: Not accepted.
  • Zero values: Not accepted.
  • Negative values: Not accepted.
  • Preferred width: The specified length is not a guaranteed exact column width.
  • Actual width: The browser adjusts column widths to fit the available space.
  • Column count: A preferred width can determine how many columns fit automatically.
  • Count constraint: A non-auto column-count can limit the number of columns.
  • Column gap: The gap affects how much space remains available for columns.
  • Shorthand: The columns property sets column-width and column-count together.
  • Shorthand resets: Omitted components return to their initial values.
  • Column fill: The column-fill property controls content distribution, not preferred column width.
  • Spanning elements: column-span: all can create full-width sections within the layout.
  • Calculated values: CSS math functions and custom properties can provide flexible preferred widths.
  • Responsive behavior: The browser can reduce the number of columns as available space decreases.
  • Single column: A container narrower than the preferred width can use one narrower column.
  • Animations: Length values can interpolate, while changes involving auto are discrete.
  • Accessibility: Maintain readable line lengths, sufficient gaps, and appropriate responsive behavior.

Use column-width when you want the browser to determine an appropriate number of columns while keeping each column near a preferred width.

Browser Support

The column-width property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.

It is part of the established CSS Multi-column Layout specification and can be used without vendor prefixes in current browsers.

Basic Example

.article {
  column-width: 250px;
  column-gap: 30px;
}

Shorthand Equivalent

.article {
  columns: 250px;
  column-gap: 30px;
}

Compatibility Considerations

Older browsers sometimes required vendor-prefixed multi-column properties. Modern browsers support the standard unprefixed syntax.

For current compatibility details, visit Can I Use? and search for column-width.

Specifications

The column-width property is defined in CSS Multi-column Layout Module Level 1.

CSS Multi-column Layout Module Level 1

The specification defines the accepted values, preferred width behavior, and interaction with column-count and the columns shorthand.