How to select elements by attribute in CSS?

Spread the love

Sometimes, we want to select elements by attribute in CSS.

In this article, we’ll look at how to select elements by attribute in CSS.

How to select elements by attribute in CSS?

To select elements by attribute in CSS, we use the attribute selector.

For instance, we write

[data-role="page"] {
  /* Styles */
}

to select all elements with the data-role attribute set to page.

Conclusion

To select elements by attribute in CSS, we use the attribute selector.

Leave a Reply

Your email address will not be published. Required fields are marked *