Hover, Focus, & Other States
Using utilities to style elements on hover, focus, and more
Overview
Similar to how Elements handles , styling elements on hover, focus, and more can be accomplished by prefixing utilities with the appropriate pseudo-class.
For a complete list of which variants are enabled by default, see the reference table at the end of this page.
Elements includes first-class support for styling elements on hover, focus, active, disabled, visited, first-child, last-child, odd-child, even-child, group-hover, group-focus, and focus-within.
If you need to target a pseudo-class that Elements doesn’t support, you can extend the supported variants by writing a custom variants or you can make a request for variant support to be added in a future release.
Hover
Add the hover:
prefix to only apply a utility on hover.
Focus
Add the focus:
prefix to only apply a utility on focus.
Active
Add the active:
prefix to only apply a utility when an element is active.
Disabled
Add the disabled:
prefix to only apply a utility when an element is disabled.
Visited
Add the visited:
prefix to only apply a utility when a link has been visited.
First-child
Add the first:
prefix to only apply a utility when it is the first-child of its parent. This is mostly useful when elements are being generated in some kind of loop.
It’s important to note that you should add any first:
utilities to the child element, not the parent element.
Last-child
Add the last:
prefix to only apply a utility when it is the last-child of its parent. This is mostly useful when elements are being generated in some kind of loop.
It’s important to note that you should add any last:
utilities to the child element, not the parent element.
Odd-child
Add the odd:
prefix to only apply a utility when it is an odd-child of its parent. This is mostly useful when elements are being generated in some kind of loop.
It’s important to note that you should add any odd:
utilities to the child element, not the parent element.
Even-child
Add the even:
prefix to only apply a utility when it is an even-child of its parent. This is mostly useful when elements are being generated in some kind of loop.
It’s important to note that you should add any even:
utilities to the child element, not the parent element.
Group-hover
If you need to style a child element when hovering over a specific parent element, add the .group
class to the parent element and add the group-hover:
prefix to the utility on the child element.
Group-focus
The group-focus
variant works just like group-hover
except for focus:
Focus-within
Note that focus-within is not supported in IE or Edge < 79.
Add the focus-within:
prefix to only apply a utility when a child element has focus.
Combining with responsive prefixes
Pseudo-class variants are also responsive, meaning you can do things like change an element’s hover style at different breakpoints for example.
To apply a pseudo-class variant at a specific breakpoint, add the responsive prefix first, before the pseudo-class prefix:
Reference Table
On this Page
v1.13.5