:target
The :target CSS pseudo-class matches the element with an ID matching the URL fragment.
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
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.
Related links
Powered by web-features