WordPress 7.0 adds support for pseudo-class selectors (:hover, :focus, :focus-visible, and :active) directly on blocks and their style variations in theme.json. Previously, this was only possible for HTML HyperText Markup Language. The semantic scripting language primarily used for outputting content in web browsers. elements like button and link under the styles.elements key. Block Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience.-level interactive states could only be achieved through custom CSS Cascading Style Sheets..
Variation-level pseudo-selectors
Block style variations can also define interactive states. This is particularly useful for variations like “Outline” that have distinct visual styles requiring different hover behaviors:
{
"styles": {
"blocks": {
"core/button": {
"variations": {
"outline": {
"color": {
"background": "transparent",
"text": "currentColor"
},
":hover": {
"color": {
"background": "currentColor",
"text": "white"
}
}
}
}
}
}
}
}
- This is a
theme.json-only API An API or Application Programming Interface is a software intermediary that allows programs to interact with each other and share data in limited, clearly defined ways.. There is no new UI User interface in Global Styles for these states in 7.0. Work on this is happening at #38277 and will be added in a future release.
- The supported pseudo-selectors for
core/button are: :hover, :focus, :focus-visible, and :active. Any others will be ignored.
- Pseudo-selectors defined at the block level and at the variation level are independent — you can define both without conflict A conflict occurs when a patch changes code that was modified after the patch was created. These patches are considered stale, and will require a refresh of the changes before it can be applied, or the conflicts will need to be resolved..
See #64263 for more details
Props to @scruffian, @onemaggie for the implementation
Props to @mikachan, @scruffian for technical review and proofreading.
#7-0, #dev-notes, #dev-notes-7-0