Class Selector

Matches the class attribute of the specified element.

Syntax

HTML .value { sRules }
Scripting N/A

Possible Values

value String that specifies the value of the "class" attribute.
sRules String that specifies one or more Cascading Style Sheets (CSS) attribute/value pairs.

Remarks

The CLASS attribute value must immediately follow the "period" (.) notation. More than one class name can be specified in one style rule; to match a subset of CLASS values, each value must be preceded by a period.

Example

For example, the following style rule matches any P element whose CLASS attribute has been assigned a space-separated list of values that include the "pastoral" and "marine" class names. This rule matches when class="pastoral aqua marine" but does not match when class="pastoral blue".

<style>
    P.pastoral.marine { color: lightseagreen; }
</style> 

Standards Information

This selector is defined in CSS, Level 1 (CSS1).

See Also

Equality [=] Attribute Selector, Existence [] Attribute Selector, Hyphen [|=] Attribute Selector, ID Selector, Prefix [^=] Attribute Selector, Substring [*=] Attribute Selector, Suffix [$=] Attribute Selector, Type Selector, Universal (*) Selector, Whitespace [~=] Attribute Selector