Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
description: >- Style elements differently based on user interaction (hover, focus, active) or target virtual parts of an element (::before, ::after) using states and selectors.
🎯 States and selectors
States and selectors let you apply styles conditionally — for example, change a button's color on hover, or add decorative content with ::before.
They live in the Style Sources dropdown alongside your Tokens. Open it by clicking the Style Sources area above the Style Panel or pressing ⌘ + Enter (Mac) / Ctrl + Enter (Windows).
Available states appear at the bottom of the Style Sources dropdown
States (pseudo-classes)
States are CSS pseudo-classes that apply styles when a condition is true, such as the user hovering over an element.
Adding a state
- Select an instance on the canvas.
- Open the Style Sources dropdown (
⌘ + Enter). - Choose a state from the list at the bottom, or type one in.
- The state appears as a tag in the style sources area. While it's active, every style you set applies only to that state.
- Click the state tag again to deselect it and return to the base (default) styles.
The :hover state is selected — styles set now only apply on hover
Custom states
You can type any valid CSS pseudo-class into the Style Sources dropdown. If it's not in the predefined list, Webstudio will accept it as a custom selector.
{% hint style="info" %}
Custom states can target descendants while staying scoped to the selected instance. For example, :hover .button targets descendants with the custom class button while the selected instance is hovered, and :hover > .icon targets only direct children with the custom class icon.
Prefer CSS variables for parent-child interactions. They keep each property on the child that uses it, can coordinate several children from one parent state, and do not couple the interaction to descendant classes or structure. Use a descendant custom state when the interaction specifically requires selector-based targeting.
Start the selector with a pseudo-class, pseudo-element, or attribute selector for the selected instance. You can then use a descendant ( ) or child (>) combinator. Selector lists, selectors that start with a type, class, or ID, and sibling combinators (+ and ~) are rejected because they can target elements outside the selected instance.
{% endhint %}
Pseudo-elements
Pseudo-elements target virtual parts of an element, such as inserting content before or after it, or styling the first letter.
Adding a pseudo-element
- Select an instance.
- Open the Style Sources dropdown (
⌘ + Enter). - Type
::before,::after, or another pseudo-element — autocomplete will suggest matches. - The pseudo-element appears as a tag. While selected, styles apply to that virtual element.
Type :: to see available pseudo-elements
Common pseudo-elements
| Pseudo-element | What it targets |
|---|---|
::before |
Virtual element inserted before the content |
::after |
Virtual element inserted after the content |
::placeholder |
Placeholder text in inputs and textareas |
::selection |
Text selected/highlighted by the user |
::first-letter |
First letter of a block element |
::first-line |
First line of a block element |
::marker |
Bullet or number of a list item |
::backdrop |
Box behind a fullscreen or modal element |
{% hint style="info" %}
::before and ::after require a content value to be visible. Set it in the Advanced section — even an empty string ("") works.
{% endhint %}
Example: decorative element with ::before
- Select a Box, Link, or Button.
- Add
::beforevia the Style Sources dropdown. - In the Advanced section, set
contentto"". - Set
displaytoblockand give it a width, height, and background. - Deselect the
::beforetag to go back to the base styles.

Select ::before to edit its styles
Combining states and tokens
States work together with Tokens. When you have a Token selected, adding a state applies styles for that state within that Token. This keeps hover styles, focus styles, and base styles neatly organized.
You can also use CSS variables to coordinate several parent-child style changes — define variables on the parent, then change their values on the :hover state so all children update at once. See Parent-child interactions for details.
Related
- CSS variables – Define reusable values and create parent-child hover interactions
- Design tokens – Package multiple styles for reuse
- Anatomy of the Webstudio builder – Learn about the Style Panel and Style Sources
- Shortcuts – Keyboard shortcuts including
⌘ + Enterfor Style Sources