CSS Tutorial

CSS Style

CSS Layout Style

CSS Float Style

CSS Reference

CSS target Selector (:target)


What is target Selector?

CSS target selector matches all element whose href hash (#) URL and that URL name exactly element id name.
This is really interesting selector check :target selector example to come exactly idea how it work.

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 1.3+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 1.3+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.

Syntax

General syntax of :target selector,

:target {
	property: value;
	property: value;
	...
}

element:target {
	property: value;
	property: value;
	...
}

Example:

Match all element whose href hash (#) URL and that URL name exactly element id name.

<style type="text/css">
    :target {
        color: red;
    }
    h3:target {
        color: blue;
    }
    p:target {
        color: orange;
    }
</style>
</head>
<body>
    <a href="#one">First</a>
    <a href="#two">Second</a>
    <a href="#three">Third</a>

    <div id="one">Third</div> 
    <h3 id="two">Second</h4> 
    <p id="three">Third</p>
</body>

Run it...   »

Example Result: