Widely availableSupported across all major browsers. Safe to use in production.

Overview

The :target CSS pseudo-class matches the element with an ID matching the URL fragment.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
1
12
1
1.3
18
2
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

CSS
:target {
  background-color: #ffffcc;
  border-left: 4px solid #f39c12;
  padding-left: 8px;
}

Live demo

sectionemphasis

CSS sectionemphasis demo.

PreviewFullscreen

hilightdisplay

CSS hilightdisplay demo.

PreviewFullscreen

tabtoggle style

CSS tabtoggle style demo.

PreviewFullscreen

Use cases

  • Using :target

    The :target CSS pseudo-class matches the element with an ID matching the URL fragment.

Cautions

  • May not be supported in older browsers.

Accessibility

  • Make sure visual changes are conveyed appropriately to assistive technology.

Powered by web-features