::column
The ::column
CSS pseudo-element represents the individual columns generated when a container is set to display its content in multiple columns via CSS multi-column layout.
Syntax
::column {
/* ... */
}
Description
When CSS multi-column layout is used to lay out a container's content in multiple columns (for example, using the column-count
property), a ::column
pseudo-element is generated to contain each individual column.
This is useful for CSS carousels — ::column
can be used to generate ::scroll-marker
pseudo-elements for each column, and set them as snap targets using CSS scroll snap.
Beyond that, the styling that can be applied to ::column
is very limited, but may be expanded in the future.
Examples
Creating a responsive carousel layout
This demo creates a responsive, CSS-only carousel. It uses the columns
property and the ::columns
pseudo-element to create arbitary content columns that span the full width of their parent scroll container, which can be scrolled between. Each column contains multiple items of content, which can vary in number depending on the viewport width.
HTML
The HTML consists of an unordered list, with each list item containing some sample content:
<ul>
...
<li>
<h2>Item 1</h2>
</li>
...
</ul>
CSS
The list is given a fixed height
and a width
of 100vw
to make it span the full width of the viewport. An overflow-x
value of scroll
is then set so that the content will scroll horizontally, and CSS scroll snap is used to snap to each item or "page" — a scroll-snap-type
value of x mandatory
is used to make the list into a scroll snap container. Finally, a columns
value of 1
is set to force the list contents to display as a single column. A text-align
value of center
is also applied, to force the contents to align with the center of the list.
ul {
width: 100vw;
height: 300px;
padding: 10px;
overflow-x: scroll;
scroll-snap-type: x mandatory;
columns: 1;
text-align: center;
}
The list items are then styled:
- A
display
value ofinline-block
is set to force the list items to sit alongside one another and make the list scroll horizontally. - A fixed
aspect-ratio
of3/4
has been set on them, to control their sizing as the list size changes, but keep their width constant while the height of the list stays constant. - A
text-align
value ofleft
is set on them to override thetext-align: center
set on the parent container, so the item content will be left-aligned. - Every even-numbered list item is given a different background-color via
:nth-child()
, so that it is easier to see the scrolling effect.
li {
list-style-type: none;
display: inline-block;
height: 100%;
aspect-ratio: 3/4;
background-color: #eee;
border: 1px solid #ddd;
padding: 20px;
margin: 0 10px;
text-align: left;
}
li:nth-child(even) {
background-color: cyan;
}
The scroll-snap-align
property is set on the ::column
pseudo-elements — which represent the content columns generated by the columns
property — so that when scrolled, the list snaps to each complete column.
ul::column {
scroll-snap-align: center;
}
We then select the ::scroll-marker
pseudo-elements of each generated column using ul::column::scroll-marker
. The look of each one is handled by setting width
, height
, background-color
, border
, and border-radius
, but we also need to set a non-none
value for the content
property so they are actually generated.
ul::column::scroll-marker {
content: "";
width: 16px;
height: 16px;
background-color: transparent;
border: 2px solid black;
border-radius: 10px;
}
Finally, we set a solid black background on the the active scroll marker using :target-current
, so you can see the current carousel scroll position:
ul::column::scroll-marker:target-current {
background-color: black;
}
Result
See Creating CSS carousels for a full explanation of the above demo.
Specifications
No specification found
No specification data found for css.selectors.column
.
Check for problems with this page or contribute a missing spec_url
to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.
Browser compatibility
See also
scroll-marker-group
::scroll-button()
::scroll-marker
::scroll-marker-group
:target-current
- Creating CSS carousels
- CSS overflow module
- CSS Carousel Gallery via chrome.dev (2025)