Sliding underline nav

Open in editor
body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: #fbfaf7; font: 500 17px system-ui, sans-serif; }
nav { display: flex; gap: 28px; }
nav a { position: relative; padding: 6px 0; color: #4a4c52; text-decoration: none; }
nav a::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: #16171a; transform: scaleX(0); transform-origin: right; transition: transform .3s; }
nav a[aria-current="page"] { color: #16171a; }
nav a[aria-current="page"]::after, nav a:hover::after { transform: scaleX(1); transform-origin: left; }
nav:has(a:hover) a[aria-current="page"]:not(:hover)::after { transform: scaleX(0); transform-origin: right; }
nav a:focus-visible { outline: 2px solid #3f6b00; outline-offset: 4px; }

Usage

Mark the current link with `aria-current="page"`. Uses `:has()` and anchor-free CSS.