--- title: Pseudoclasses slug: Web/CSS/Pseudoclasses tags: - CSS - Pseudoclasse - Referencia - Resumo - Seletores - Sinopse translation_of: Web/CSS/Pseudo-classes ---
A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, {{CSSxRef(":hover")}} can be used to change a button's color when the user's pointer hovers over it.
/* Any button over which the user's pointer is hovering */ button:hover { color: blue; }
Pseudo-classes let you apply a style to an element not only in relation to the content of the document tree, but also in relation to external factors like the history of the navigator ({{CSSxRef(":visited")}}, for example), the status of its content (like {{CSSxRef(":checked")}} on certain form elements), or the position of the mouse (like {{CSSxRef(":hover")}}, which lets you know if the mouse is over an element or not).
Nota: In contrast to pseudo-classes, pseudo-elements can be used to style a specific part of an element.
selector:pseudo-class { property: value; }
Like regular classes, you can chain together as many pseudo-classes as you want in a selector.
Especificação | Estado | Comentário |
---|---|---|
{{SpecName("Fullscreen")}} | {{Spec2("Fullscreen")}} | Defined :fullscreen . |
{{SpecName("HTML WHATWG", "#pseudo-classes")}} | {{Spec2("HTML WHATWG")}} | Defines when particular selectors match HTML elements. |
{{SpecName("CSS4 Selectors")}} | {{Spec2("CSS4 Selectors")}} | Defined :any-link , :blank , :local-link , :scope , :drop , :current , :past , :future , :placeholder-shown , :user-invalid , :nth-col() , :nth-last-col() and :matches() .No significant change for pseudo-classes defined in {{SpecName("CSS3 Selectors")}} and {{SpecName("HTML5 W3C")}} (though semantic meaning not taken over). |
{{SpecName("HTML5 W3C")}} | {{Spec2("HTML5 W3C")}} | Copies the relevant section from the canonical (WHATWG) HTML spec. |
{{SpecName("CSS3 Basic UI")}} | {{Spec2("CSS3 Basic UI")}} | Defined :default , :valid , :invalid , :in-range , :out-of-range , :required , :optional , :read-only and :read-write , but without the associated semantic meaning. |
{{SpecName("CSS3 Selectors")}} | {{Spec2("CSS3 Selectors")}} | Defined :target , :root , :nth-child() , :nth-last-of-child() , :nth-of-type() , :nth-last-of-type() , :last-child , :first-of-type , :last-of-type , :only-child , :only-of-type , :empty and :not() .Defined the syntax of :enabled , :disabled , :checked , and :indeterminate , but without the associated semantic meaning.No significant change for pseudo-classes defined in {{SpecName('CSS2.1')}}. |
{{SpecName("CSS2.1")}} | {{Spec2("CSS2.1")}} | Defined :lang() , :first-child , :hover , and :focus .No significant change for pseudo-classes defined in {{SpecName('CSS1')}}. |
{{SpecName("CSS1")}} | {{Spec2("CSS1")}} | Defined :link , :visited and :active , but without the associated semantic meaning. |