::scroll-marker-group
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The ::scroll-marker-group
CSS pseudo-element is a container generated inside a scroll container, which contains any ::scroll-marker
pseudo-elements generated on the descendants of the scroll container.
Syntax
::scroll-marker-group {
/* ... */
}
Description
A scroll container's ::scroll-marker-group
pseudo-element represents a scroll marker group. This is a container that automatically has any ::scroll-marker
pseudo-elements generated on its descendants placed into it. This allows them to be positioned and laid out as a group, and is typically used when creating a CSS carousel, to provide a scroll position indicator. The individual scroll markers can also be used to navigate to their associated content items.
The scroll-marker-group
property must be set to a non-none
value on the scroll container for a ::scroll-marker-group
pseudo-element to be generated; the chosen value determines where the scroll marker group appears in the carousel's tab order and layout box order (but not DOM structure) — before
puts it at the start, while after
puts it at the end.
It is a best practice to match the visual rendering position of the scroll marker group with the tab order. When placing the group at the start of the content, put it at the beginning of the tab order using before
. When placing the group at the end of the content, put it at the end of the tab order using after
.
Accessibility-wise, the scroll marker group and contained scroll markers are rendered with tablist
/tab
semantics. When you Tab to the group, it behaves like a single item (that is, another press of the Tab key will move past the group to the next item), and you can move between the different scroll markers using the left and right (or up and down) cursor keys.
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
In this demo, the list's scroll-marker-group
property is set to after
, so the ::scroll-marker-group
pseudo-element is placed after the list's DOM content in the focus order:
ul {
scroll-marker-group: after;
}
Next, the list's ::scroll-marker-group
pseudo-element is positioned relative to the carousel using CSS anchor positioning. It is horizontally centered on the carousel using a justify-self
value of anchor-center
. The group is laid out using flexbox, with a justify-content
value of of center
and a gap
of 20px
so that its children (the ::scroll-marker
pseudo-elements) are centered inside the ::scroll-marker-group
with a gap between each one.
ul::scroll-marker-group {
position: absolute;
position-anchor: --myCarousel;
top: calc(anchor(bottom) - 70px);
justify-self: anchor-center;
display: flex;
justify-content: center;
gap: 20px;
}
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
Specification |
---|
CSS Overflow Module Level 5 # scroll-marker-group-pseudo |
Browser compatibility
See also
scroll-marker-group
::scroll-button()
::scroll-marker
::column
:target-current
- Creating CSS carousels
- CSS overflow module
- CSS Carousel Gallery via chrome.dev (2025)