MDN self-hosted library · e01.org

Using the :target pseudo-class in selectors

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

css
h2:target {
  outline: 2px solid;
}
css
#reference:target {
  background-color: yellow;
}
css
:target {
  color: red;
}
html
<h4 id="one">…</h4>
<p id="two">…</p>
<div id="three">…</div>
<a id="four">…</a> <em id="five">…</em>

<a href="#one">First</a>
<a href="#two">Second</a>
<a href="#three">Third</a>
<a href="#four">Fourth</a>
<a href="#five">Fifth</a>