columns
Example
.articles {
column-count: 3;
}.articles {
columns: 16rem 3;
column-gap: 2rem;
}With a width and a count, the browser uses at most three columns and only as many as fit at about 16rem each.
Common mistakes
- Three fixed columns become unreadably narrow on phones.
- A card is cut in half and continues at the top of the next column.
Key points
- The value combines a minimum width and a maximum count, like '16rem 3', so columns drop on small screens.
- Items that must not split across columns have
break-inside: avoid. - Card grids that read left to right use Grid, since columns fill top to bottom.
Interview questions
Can I use CSS columns for a masonry layout?
It looks similar, but items flow down each column first, so the reading order goes top to bottom instead of across rows.
What is the difference between columns and grid?
Columns flow one continuous content stream into columns. Grid places items in rows and columns you define.