Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

::scroll-marker CSS Pseudo Element

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The ::scroll-marker pseudo-element is a specialized CSS feature that allows developers to style markers within scrollable containers, particularly when using the CSS Scroll-Linked Animations specification. It is primarily used in conjunction with elements that are scrollable, such as those with the CSS overflow properties, to visually indicate the position or presence of certain points along the scrollable content. This pseudo-element is often seen in contexts like scroll-snapping, custom scrollbars, or any situation where precise control over the visual markers within a scrollable area is required.

The ::scroll-marker pseudo-element can be attached to elements with a scrolling context, including block containers or elements with a overflow set to auto or scroll. When used, it allows styling of these scroll indicators in ways similar to other pseudo-elements like ::before and ::after, providing options for visual customization such as color, size, and shapes without altering the underlying document structure.

One practical application of ::scroll-marker is in enhancing the user experience for scrollable lists, tables, or code blocks. For instance, when a developer wants to highlight certain positions in a long list, ::scroll-marker can be styled to create dots, bars, or other visual cues along the scrollbar track. This can also complement the behavior of scrollbar-track styling.

Here is an example demonstrating its basic usage:

.scrollable-container::scroll-marker {
    background-color: #ff6600;
    height: 8px;
    width: 8px;
    border-radius: 50%;
}
<div class="scrollable-container">
  <p>Item 1</p>
  <p>Item 2</p>
  <p>Item 3</p>
  <!-- more items -->
</div>

In this example, each scroll marker inside the .scrollable-container will be rendered as a small, orange circular indicator, providing a visual cue for scrollable positions.

Styling of ::scroll-marker supports various CSS properties, including background-color, height, width, and border-radius. However, it is important to note that support for this pseudo-element is limited and may vary across browsers, as it is considered part of experimental scroll-linked features.

Because it is a visual enhancement pseudo-element, ::scroll-marker does not affect the layout of the document itself, similar to other pseudo-elements like ::before. It serves purely decorative and informational purposes for the scrollable container.

Syntax

::scroll-marker {
  /* ... */
}

Example

<ul class="carousel">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
</ul>
/* 1. The Scroll Container */
.carousel {
display: flex;
overflow-x: auto;
scroll-snap-type: x mandatory;
gap: 10px;
padding: 20px;
list-style: none;

/* Required: Creates the container for the markers */
scroll-marker-group: after;
}

/* 2. The Items (Targets) */
.carousel li {
flex: 0 0 80%; /* Each item takes 80% width */
height: 170px;
background: #3498db;
color: white;
display: flex;
align-items: center;
justify-content: center;
scroll-snap-align: center;
border-radius: 8px;
}

/* 3. The Individual Markers */
/* Generated automatically for every <li> inside the container */
.carousel li::scroll-marker {
content: ""; /* Required to show the marker */
width: 12px;
height: 12px;
background-color: #ccc;
border-radius: 50%;
display: inline-block;
cursor: pointer;
}

/* 4. The Marker Group Styling */
/* This styles the wrapper that holds all the dots */
.carousel::scroll-marker-group {
display: flex;
justify-content: center;
gap: 10px;
margin-top: 15px;
}

/* 5. Active State */
/* Styles the marker belonging to the item currently in view */
.carousel li::scroll-marker:target-current {
background-color: #3498db;
transform: scale(1.2);
}

Browser Support

The following information will show you the current browser support for the CSS ::scroll-marker pseudo element. Hover over a browser icon to see the version that first introduced support for this CSS psuedo element.

This psuedo element is supported in some modern browsers, but not all.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 1st January 2026

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!