:target-after CSS pseudo-class

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The :target-after CSS pseudo-class selects scroll markers that come after the active scroll marker (the one that currently matches :target-current) within a scroll marker group. You can use this selector to style navigation items that come after the current navigation position within a scroll marker group.

Note: The :target-after pseudo-class is only valid on ::scroll-marker pseudo-elements and elements that have been designated as scroll markers via the scroll-target-group property.

Syntax

css
:target-after {
  /* ... */
}

Examples

Styling navigation items before and after the active scroll marker

In this example, we use the :target-before and :target-after pseudo-classes to highlight the scroll markers before and after the active one, indicating items the user has already viewed and those that are still to come.

HTML

The markup contains a table of contents created using an ordered list (<ol>/<li>) and <a> elements. This is followed by a series of <section> elements containing content.

html
<nav id="toc">
  <ol>
    <li><a href="#intro">Introduction</a></li>
    <li><a href="#ch1">Chapter 1</a></li>
    <li><a href="#ch2">Chapter 2</a></li>
    <li><a href="#ch3">Chapter 3</a></li>
    <li><a href="#ch4">Chapter 4</a></li>
  </ol>
</nav>
<section id="intro" class="chapter">
  <h1>Prose of the century</h1>
  <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla luctus
    aliquam dolor, eu lacinia lorem placerat vulputate. Duis felis orci,
    pulvinar id metus ut, rutrum luctus orci. Cras porttitor imperdiet nunc, at
    ultricies tellus laoreet sit amet.
  </p>
</section>
<section id="ch1" class="chapter">
  <h2>Chapter 1</h2>

  <!-- ... -->
</section>
<section id="ch2" class="chapter">
  <h2>Chapter 2</h2>

  <!-- ... -->
</section>

<!-- ... -->

CSS

We've set scroll-target-group: auto on the <ol> to turn it into a scroll marker group container and let the browser determine which <a> element is the active scroll marker at any given time (that is, which link's target is currently in view). We then style the :target-current pseudo-class with a red color so that it stands out clearly.

css
ol {
  scroll-target-group: auto;
}

:target-current {
  color: red;
}

Finally, we use the :target-before pseudo-class to style all <a> elements before the active scroll marker with a gray color and strike-through, to make them look completed/finished, and we use the :target-after pseudo-class to style all <a> elements after the active scroll marker with a bright underline.

css
a:target-before {
  color: gray;
  text-decoration: line-through;
}

a:target-after {
  text-decoration: underline orange 2px;
}

Result

Try navigating either by clicking the links or by scrolling. In both cases, you'll see that the red text color moves between the links to match the section currently in view. The links before and after the current red link also update to use the styles defined in the a:target-before and a:target-after rules.

Specifications

Specification
CSS Overflow Module Level 5
# selectordef-target-after

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
target-after
Experimental
Chrome – Full support
Chrome 142 (Release date: 2025-10-28)
footnote Full support
Edge – Full support
Edge 142 (Release date: 2025-10-31)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 126 (Release date: 2026-01-08)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 142 (Release date: 2025-10-28)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 93 (Release date: 2025-11-25)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote No support
WebView Android – Full support
WebView Android 142 (Release date: 2025-10-28)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

See also