freeCodeCamp/guide/english/css/selectors/attribute/class-equals/index.md

426 B

title
Class Equals

Class Equals

To select an item with a class attribute, you use the following selector:

p[class="happy"] {
    color: yellow;
}

This selector is not commonly used, as there is a general class selector. We can rewrite the above selector like this:

p.happy {
    color: yellow;
}

More Information:

https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors