CSS Basics Web development basics

CSS attribute selectors

CSS attribute selectors are used to style the elements that have a particular property or attribute.

CSS attribute selectors

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

Result:


I do not have alt attribute

CSS attribute selecotrs
I have alt attribute


CSS [attribute=”value”] Selector

CSS attribute selectors can also be used to style the elements that have a particular value for a property or attribute.
For example:

Result:

CSS [attribute^=”value”] Selector

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

Result:

Hi

CSS [attribute$=”value”] Selector

The [attribute$="value"] selector is used to select elements whose attribute value ends with a specified value.
For example:

Result:

Hi

CSS [attribute*=”value”] Selector

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

Result:

Hi
Hi
Hi
Hi
Hi