Utilizor
Contact Us

CSS Attr Selectors

Style HTML elements with specific attributes or attribute values.

CSS Attribute Selectors

Style HTML elements with specific attributes or attribute values.

Example 1: [attribute] Selector

The [attribute] selector is used to select elements with a specified attribute.

The links with a target attribute gets a yellow background:

w3schools.com
disney.com
wikipedia.org

Example 2: [attribute="value"] Selector

The [attribute="value"] selector is used to select elements with a specified attribute and value.

The link with target="_blank" gets a yellow background:

w3schools.com
disney.com
wikipedia.org

Example 3: [attribute~="value"] Selector

The [attribute~="value"] selector is used to select elements with an attribute value containing a specified word.

The image with the title attribute containing the word "flower" gets a yellow border:

Example 4: [attribute|="value"] Selector

The [attribute|="value"] selector is used to select elements with the specified attribute starting with the specified value.

Welcome

Hello world!

Are you learning CSS?

Example 5: [attribute^="value"] Selector

The [attribute^="value"] selector is used to select elements whose attribute value begins with a specified value.

Welcome

Hello world!

Are you learning CSS?

Example

a[target] {
  background-color: yellow;
}

a[target="_blank"] {
  background-color: yellow;
}