- Home
- /
- Tutorials
- /
- CSS Tutorial
- /
- Multi-column Layout
CSS Layout
Multi-column Layout
Flow long-form content through balanced columns and control how elements break across them. The examples cover automatic column count, preferred column width, column rules, spanning headings, and fragmentation controls.
CSS columns flow one long piece of text into side-by-side columns, like a newspaper. They are made for reading content, not for laying out separate boxes on a page.
Columns make good use of a wide screen for articles, glossaries and long lists. The trade-off is that the browser decides where the text breaks from one column to the next. You can ask it not to split a figure or a heading, but you cannot place items exactly. This lesson connects with Normal Flow and Responsive Layout.
Let the browser decide the number of columns
Example
css
.article {
columns: 18rem 3;
column-gap: 2rem;
column-rule: 1px solid #d8dee9;
}
.article h2 {
column-span: all;
}columns: 18rem 3 reads as "columns about 18rem wide, at most 3 of them". On a wide screen you get three. On a phone, there is only room for one, so you get one, with no media query. column-span: all lets a heading stretch across every column.
Stop things from being split
Example
css
.article figure,
.article blockquote {
break-inside: avoid;
}
.article h3 {
break-after: avoid;
}break-inside: avoid keeps a figure or quote in one piece. break-after: avoid stops a heading from sitting alone at the bottom of a column with its text in the next one.
How to Make 2 Columns in CSS
Set column-count: 2 to flow text into two columns. With columns: 2 220px the browser uses at most two columns and drops to one when there is no room for 220px each, so no media query is needed.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example</title>
<style>
.text { columns: 2 220px; column-gap: 24px; column-rule: 1px solid #cbd5e1; }
</style>
</head>
<body>
<div class="text">
<p>The first paragraph starts in the first column.</p>
<p>The text continues and the browser balances the height.</p>
<p>Make the preview narrow to see one column.</p>
<p>Make it wide again to see two.</p>
</div>
</body>
</html>Split a ul List into Columns
Apply columns to the list and stop each item from being cut in half with break-inside: avoid.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example</title>
<style>
ul { columns: 3 120px; }
li { break-inside: avoid; }
</style>
</head>
<body>
<ul>
<li>HTML</li><li>CSS</li><li>JavaScript</li>
<li>React</li><li>DSA</li><li>Git</li>
</ul>
</body>
</html>CSS Columns or Grid?
| You have | Use |
|---|---|
| One long text or list that should flow | CSS columns |
| Separate boxes in rows and columns | CSS Grid |
| One row of items | Flexbox |
For page layouts, continue with CSS Grid Columns.
Multi-column Properties
| Property | Purpose | Example |
|---|---|---|
| columns | Sets a preferred column width and count. | columns: 16rem 3 |
| column-gap | Sets space between columns. | column-gap: 2rem |
| column-rule | Draws a rule between columns. | column-rule: 1px solid #ccc |
| break-inside | Controls fragmentation inside an element. | break-inside: avoid |
Complete Example
Complete runnable example
html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multi-column Layout example</title>
<style>
* { box-sizing: border-box; }
body {
margin: 0;
padding: 2rem;
font-family: system-ui, sans-serif;
line-height: 1.5;
}
main { max-width: 70rem; margin-inline: auto; }
article, section, aside, form, .card, .panel {
padding: 1rem;
border: 1px solid #cbd5e1;
border-radius: 0.6rem;
}
.article {
columns: 18rem 3;
column-gap: 2rem;
column-rule: 1px solid #d8dee9;
}
.article h2 {
column-span: all;
}
.article figure,
.article blockquote {
break-inside: avoid;
}
.article h3 {
break-after: avoid;
}
</style>
</head>
<body>
<main class="article"><h2>Multi-column article</h2><p>Long-form text can flow through balanced columns. The browser decides where each line and paragraph continues.</p><blockquote>Important quotations can avoid an awkward split.</blockquote><p>Add enough real content before deciding how many columns are comfortable to read.</p></main>
</body>
</html>Browser Support
Feature | Chrome | Edge | Firefox | Safari |
|---|---|---|---|---|
| columns | 50 | 12 | 52 | 9 |
Versions show the first stable desktop release with unprefixed support. Data source: MDN Browser Compatibility Data 8.0.8. A partial-support note is included where it changes how the example behaves.
Watch out for
- Very tall columns on a phone make people scroll down, then back up to the top of the next column. If the text is long, one column is often kinder on small screens.
- Columns are for one stream of content. If each box needs its own place, use Grid.
Multi-column Layout exercises
Three columns
Split the text box into 3 columns.
The HTML your code works on
<div class="text">
<h2>News</h2>
<p>Lots of text that does not fit into this small box at all, so it has to go somewhere. Lots of text that does not fit into this small box at all, so it has to go somewhere. Lots of text that does not fit into this small box at all, so it has to go somewhere.</p>
</div>Result
