...

/

Using Attribute Selectors

Using Attribute Selectors

Learn how to work with elements based on HTML attributes.

Using attribute selectors

Elements can have attributes that provide extra details.

The following example shows an href attribute in an a (link) tag:

<a href="https://google.com">This is a link</a>

We use CSS attribute selectors to target such elements with their specific attributes. For example:

a[href="https://www.google.com"] {
  color: #FFFF00;
}

Here, we have an exact match selection that selects links with the exact href value of “https://www.google.com”.

Let’s learn how to use these very useful selectors!

Types of attribute selectors

There are several different types of attribute selectors. They’re classified as either presence and value selectors or substring matching selectors. The syntax for each selector begins with the particular attribute name and ends with an equal sign (=), followed by the attribute value(s). The selector type ...