Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Navigation and links in CSS

CSS controls the appearance of links and their interaction states, not the navigation destination itself. Learn link selectors, visible focus, and highlighting the element addressed by a URL fragment.

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

Syntax

a:any-link { /* a elements that are hyperlinks, visited or unvisited */ }
a:link { /* unvisited links */ }
a:visited { /* visited links, subject to privacy restrictions */ }
a:hover { /* pointer hover */ }
a:active { /* activation in progress */ }
a:focus-visible { /* browser-indicated focus */ }
:target { /* the document's target element, if any */ }

Navigation and links covers styling hyperlinks and location or interaction feedback. In the example, href="#details" supplies the destination; CSS changes presentation rather than replacing navigation.

:any-link selects hyperlinks regardless of history. :link means unvisited and :visited means visited, subject to privacy protections. Do not assume appearance reliably reveals user history.

:hover concerns pointing; :active means activation in progress, not the current page. :focus means input focus, while :focus-visible matches when the browser determines that a focus indicator should appear. Do not remove focus indicators without a replacement.

:target matches the document’s target element, if any, not the link pointing to it. Activating the example link highlights the details section. Changing the URL fragment with history.pushState() or history.replaceState() does not update the document’s target element. As a result, :target can continue to highlight a different element from the one indicated by the current URL fragment.

A CSSWG draft is not evidence of browser support; the example needs local verification.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Link states</title>
<style>
  a:any-link { color: #0645ad; text-decoration: underline; }
  a:hover { text-decoration: none; }
  a:focus-visible { outline: 3px solid #111; outline-offset: 3px; }
  a:active { color: #a00000; }
  :target { background-color: #fff2a8; }
</style>
<nav aria-label="Sections">
  <a href="#details">Details</a>
</nav>
<section id="details">
  <h1>Details</h1>
  <p>Fragment target.</p>
</section>
</html>

Result

Initially, Details is a blue, underlined link and the section has no authored background. Hover removes the underline. Keyboard focus should show an outline when the browser indicates visible focus. Activating the link changes the URL fragment to #details and gives the section a pale yellow background.

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