CSS/Selectors/attribute selector/attribute=value

From Web Education Community Group
< CSS‎ | Selectors
Jump to: navigation, search

[attributename="val"]

This selector represents an element with the "attributename" attribute whose value is exactly "val".

Syntax

elementname[attributename="val"]{ properties }

Example

In the following example, the selector represents a span element whose class attribute has exactly the value "example":

[style.css]

 span[class="example"]{
   color: red;
   font-size: 1.2em;
 }

[index.html]

<body>
  <p>This is a <span class="example">paragraph</span>.</p>
  <p>This is a <span class="test">paragraph</span>.</p>
</body>

Css3 selectors att 002.png

CSS defines the attribute selector in 6.3.1. Attribute presence and value selectors.