CSS :target Selector

The :target pseudo selector in CSS matches when the hash in the URL and the id of an element are the same.

URLs with an # followed by an anchor name link to a certain element within a document. The element being linked to is the target element.The :target selector can be used to style the current active target element.

When a URL points at a specific piece of a document, it can be difficult for the user to notice. Find out how you can use some simple CSS to draw attention to the target of a URL and improve the user's experience.

CSS Syntax

:target {css declarations;}

Example -