Back to CSS Notes
Topic #98

Advanced Attr Selectors

Advanced attribute selectors match substrings and patterns in attribute values. They unlock powerful styling without extra classes.


Advanced Attribute Selectors

Advanced attribute selectors match elements based on partial attribute values using special operators.


CSS [attribute^="value"] Selector

The [attribute^="value"] selector is used to select elements with the specific attribute, whose value starts with a specific value.

The following example selects all elements with a class attribute value that starts with "top":

Example

[class^="top"] {
  background: yellow;
}

CSS [attribute$="value"] Selector

The [attribute$="value"] selector is used to select elements whose attribute value ends with a specific value.

The following example selects all elements with a class attribute value that ends with "test":

Example

[class$="test"] {
  background: yellow;
}

CSS [attribute*="value"] Selector

The [attribute*="value"] selector is used to select elements whose attribute value contains a specific value.

The following example selects all elements with a class attribute value that contains "te":

Example

[class*="te"] {
  background: yellow;
}

Style Form Elements With Attribute Selectors

The CSS attribute selectors can be useful for styling form elements, based on input type:

Example

  input[type="text"] {
  width: 150px;
  padding: 6px;

  margin-bottom: 10px;
  background-color: pink;
}

  input[type="button"] {
  width: 100px;
  padding: 6px;

  background-color: lightgreen;
}

Tip: Visit our CSS Forms Tutorial for more examples on how to style forms with CSS.


All CSS Attribute Selectors

Selector Description
[attribute] Select elements with a specific attribute
[attribute=value] Select elements with a specific attribute with an exact value
[attribute~=value] Select elements with an attribute value containing a specific word
[attribute|=value] Select elements with the value or value followed by hyphen
[attribute^=value] Select elements whose value starts with a specific value
[attribute$=value] Select elements whose value ends with a specific value
[attribute*=value] Select elements whose value contains a specific value

Want to go beyond the notes?

Join Coding Now Tech Institute's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Advanced Attr Selectors – FAQs

Quick answers about learning Advanced Attr Selectors in CSS.

This free note from Coding Now Tech Institute explains Advanced Attr Selectors in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on Coding Now Tech Institute, including Advanced Attr Selectors, is 100% free with no signup required.
With focused practice, most students grasp Advanced Attr Selectors in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now