CSS [Attribute$="Value"] Selector

The [attribute$="value"] selector is used to select elements whose attribute value ends with a specified value. The following example selects all elements with a class attribute value that ends with "test":

HTML file: Displayed by browser:
<style>
[class$="test"] {
    background: yellow;
}
</style>
<body>
<div class="first_test">The first div element.</div>
<div class="second">The second div element.</div>
<div class="my-test">The third div element.</div>
<p class="mytest">This is some text in a paragraph.</p>
</body>
The first div element.
The second div element.
The third div element.

This is some text in a paragraph.

Note: The value does not have to be a whole word.

Back button Table of Contents Next button