The :Target Anchor Highlight

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. This example will highlight an active HTML anchor:

HTML file: Displayed by browser:
<style>
:target {
    border: 2px solid #d4d4d4;
    background-color: #e5eecc;
}
</style>
<body>
<h1>Highlight HTML Anchors</h1>
<p><a href="#news1">Jump to New content 1</a></p>
<p><a href="#news2">Jump to New content 2</a></p>
<p>Click on the links above and the :target selector highlight the current active HTML anchor.</p>
<p id="news1"><b>New content 1...</b></p>
<p id="news2"><b>New content 2...</b></p>
</body>

Highlight HTML Anchors

Jump to New content 1

Jump to New content 2

Click on the links above and the :target selector highlight the current active HTML anchor.

New content 1...

New content 2...

Note: Internet Explorer 8 and earlier versions do not support the :target selector.

Back button Table of Contents Next button