CSS Attribute Selectors

Next ❯CSS3 Background

Used to select elements you want to style with the help of attribute or its values

  • turned_in_notProperty
    • [attribute]
    • [attribute="value"]
    • [attribute|="value"]
    • [attribute~="value"]
    • [attribute^="value"]
    • [attribute$="value"]
    • [attribute*="value"]

[attribute]

It selects all elements having specified attribute

/*Syntax*/

selector[attribute] {
  /*css properties*/
}

[attribute="value"]

It selects all elements having specified attribute with specified value

/*Syntax*/

selector[attribute="value"] {
  /*css properties*/
}

[attribute|="value"]

It selects all elements having specified attribute with specified value equal to or followed by a hyphen(-)

/*Syntax*/

selector[attribute|="value"]{
  /*css properties*/
}

<p className="ab">Hello friends!</p>

<p className="ab-cd">Good Luck !</p>


[attribute~="value"]

It selects all elements having specified attribute containing a specified value

/*Syntax*/

selector[attribute~="value"]{
  /*css properties*/
}

<p className="aa ab">Hello friends!</p>

<p className="cd de">Good Luck !</p>


[attribute^="value"]

It selects all elements having specified attribute begins with specified value

/*Syntax*/

selector[attribute^="value"]{
  /*css properties*/
}

<p className="abc">Hello friends!</p>

<p className="xyz">Good Luck !</p>


[attribute$="value"]

It selects all elements having specified attribute ends with specified value

/*Syntax*/

selector[attribute$="value"]{
  /*css properties*/
}

[attribute*="value"]

It selects all elements having specified attribute which contains substring as specified value

/*Syntax*/

selector[attribute*="value"]{
  /*css properties*/
}

  • CSS3 Background
❮ Prev Pseudo Elements
Next ❯CSS3 Background
receipt