Attribute Selectors in CSS


You can also apply styles to HTML elements with particular attributes. The style rule below will match all the input elements having a type attribute with a value of text 

input[type = "text"]{
   color: #000000;
}

The following are the rules applied to attribute selector.

  •  p[lang] - Selects all paragraph elements with a lang attribute.
  •  p[lang="fr"] - Selects all paragraph elements whose lang attribute has a value of exactly "fr".
  •  p[lang~="fr"] - Selects all paragraph elements whose lang attribute contains the word "fr".
  •  p[lang|="en"] - Selects all paragraph elements whose lang attribute contains values that are exactly "en", or begin with "en-".

Updated on: 30-Jan-2020

349 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements