CSS Selector - How to use CSS attribute equal Selector [attribute=value]








The [attribute=value] selector selects elements with the specified attribute and value.

element1[attr="value"] is also called Exact Attribute Value Selector.

element1[attr="value"] selects any element based on the precise and complete value of an attribute.

Examples:

a[rel="Start"]  {font-weight: bold;}
p[class="urgent"] {color: red;}

Summary

CSS Version
2

CSS Syntax

[attribute=value] { 
   style properties 
}

Browser compatibility

[attribute=value] Yes 7.0 Yes Yes Yes




Example

An example showing how to use [attribute=value] CSS selector.

<!DOCTYPE html>
<html>
<head>
<style>
a[target=_blank]<!--  www. j  a  v  a  2s .  co m-->
{
   background-color:red;
}
</style>
</head>
<body>

<a href="http://java2s.com" target="_top">java2s.com</a>

</body>
</html>

Click to view the demo