asp.net.ph

Skip Navigation LinksAbakada: Back to Basics > Language References > CSS Properties > Pseudo-Classes > target Pseudo-class

:target Pseudo-class


Sets the style of target elements in a document.

Syntax

selector:target { property: value; }

Possible Values

property Any valid CSS property.
value Any of the range of values available to the corresponding property.

Remarks

The :target pseudo-class applies styles to a named location within the same HTML document.

In many cases, the target of a link may be set to a destination element within the same document.

To enable an element as a destination, the element must be given an anchor name using the element’s id attribute.

<h2 id="section2">How Links Work</h2>
... contents of section 2 here below ...

This creates a destination anchor for the heading element that can be the target of any other link, such as an entry in a file’s table of contents.

The following shows how a link may be used to access the named section within the same page.

<a href="#section2">Section 2: How Links Work</a>

The pound sign (#) refers to a fragment identifier that points to a named location on the file. Web Authoring Basics has more information on fragment identifiers.

The :target pseudo-class allows styling a link’s destination or target element, in this case, the <h2> heading.

The syntax for using the :target pseudo-class is straightforward. Nothing precedes the pseudo-class.

For example, to change the color of a destination anchor on a page:

:target { color: #005 }

Please see Linking to a location within a document for further information.

Example

The following demonstrates use of the :target pseudo-class in an embedded stylesheet to set the color of a destination element on the same page.

 Show me 

External References

See Also

:active   :focus   :hover   :link   :visited



Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note