Scroll marker target pseudo-classes
The :target-current CSS pseudo-class selects the active scroll marker (as in ::scroll-marker), while the :target-after and :target-before pseudo-classes select the inactive markers preceding and following the active scroll marker.
Overview
The :target-current CSS pseudo-class selects the active scroll marker (as in ::scroll-marker), while the :target-after and :target-before pseudo-classes select the inactive markers preceding and following the active scroll marker.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
:target-after Experimental | 142 | 142 | | | 142 | |
| Other | ||||||
css.selectors.target-before Experimental | 142 | 142 | | | 142 | |
css.selectors.target-current Experimental `:target-current` | 135 | 135 | | | 135 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
CSS
.item::scroll-marker:target-current {
background: #3498db;
}
.item::scroll-marker:target-before {
opacity: 0.5;
} Live demo
Use cases
Using Scroll marker target pseudo-classes
The :target-current CSS pseudo-class selects the active scroll marker (as in ::scroll-marker), while the :target-after and :target-before pseudo-classes select the inactive markers preceding and following the active scroll marker.
Cautions
- Limited browser support. Check compatibility before use.
Accessibility
- Make sure visual changes are conveyed appropriately to assistive technology.
Related links
Powered by web-features