Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

:target-after — markers after the active scroll marker

The :target-after pseudo-class selects markers following the active marker within the same scroll marker group.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

:target-after

:target-after selects all markers after the active marker in the same group, using flat tree order rather than visual position. It takes no arguments.

:target-current identifies the active marker; :target-before selects earlier ones. In the example, scroll-target-group: auto groups the links. The selector styles links, not destination sections; it is not equivalent to :target.

This feature belongs to the CSS Overflow Module Level 5 draft. Check support in the target browser. Retain working links as the baseline; recognizing the selector alone does not prove correct behavior.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>:target-after demo</title>
<style>
  body { margin: 0; font-family: sans-serif; }
  nav {
    position: fixed;
    top: 0;
    right: 0;
    padding: 1rem;
    background: white;
    scroll-target-group: auto;
  }
  nav a { display: block; color: black; }
  nav a:target-current { font-weight: bold; }
  nav a:target-after { color: purple; }
  section { height: 100vh; padding: 1rem; box-sizing: border-box; }
</style>
<nav aria-label="Sections">
  <a href="#one">One</a>
  <a href="#two">Two</a>
  <a href="#three">Three</a>
</nav>
<main>
  <section id="one">One</section>
  <section id="two">Two</section>
  <section id="three">Three</section>
</main>
</html>

Result

With the required features supported, after clicking Two and scrolling settles: Two is bold, Three is purple, and One is black.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources