CSS :target Pseudo-class
Example
Style the current active target element:
:target
{
border: 2px solid darkorange;
background-color: beige;
}
Try it Yourself »
Definition and Usage
The :target
pseudo-class is used to style the current active target element.
Tip: An URL with an #, followed by an anchor name, links to a specific element within the document. The element being linked to is the target element.
Version: | CSS3 |
---|
Browser Support
The numbers in the table specifies the first browser version that fully supports the pseudo-class.
Pseudo-class | |||||
---|---|---|---|---|---|
:target | 4 | 9 | 3.5 | 3.2 | 9.5 |
CSS Syntax
:target {
css declarations;
}
More Examples
Example
Create a tabbed menu:
.tab div {
display: none;
}
.tab div:target {
display: block;
}
Try it Yourself »
Example
Create a modal (dialog box):
/* The modal's background */
.modal {
display: none;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0, 0, 0);
background-color: rgba(0, 0, 0, 0.4);
}
/* Display the modal when targeted */
.modal:target {
display: table;
position: absolute;
}
/* The modal box */
.modal-dialog {
display: table-cell;
vertical-align: middle;
}
/* The modal's content */
.modal-dialog .modal-content {
margin: auto;
background-color: #f3f3f3;
position: relative;
padding: 0;
outline: 0;
border: 1px #777 solid;
text-align: justify;
width: 80%;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
Try it Yourself »