English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Complete List of CSS Properties

CSS3 :target selector

:target CSS pseudo-class represents a unique page element (target element) whose id matches the current URL fragment .

Complete CSS Selector Reference Manual

Online Example

Highlight the active HTML anchor:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Basic Tutorial(oldtoolbag.com)</title>/title> 
<style>
:target
{
    border: 2px solid red;
    background-color: yellow;
}
</style>
</head>
<body>
<h1>This is a title</h1>
<p><a href="#news1">Jump to content 1</a></p>
<p><a href="#news2">Jump to content 2</a></p>
<p>Click the link above, then:target selector highlights the current active HTML anchor.</p>
<p id="news1><b>New content 1...</b></p>
<p id="news2><b>New content 2...</b></p>
<p><b>Attention:</b>IE 8 and earlier versions of browsers do not support the :target selector.</p>
</body>
</html>
Test to see ‹/›

Definition and Usage

:target

# The name of the anchor is the URL that links to an element in a file. The element is linked to the target element.

The :target selector can be used to style the current active target element.

Browser Compatibility

The numbers in the table indicate the first browser version that supports the attribute.

Selector




:target4.09.03.53.29.6

Complete CSS Selector Reference Manual