Skip to main content

Understanding States and Variants

Learn how to create and manage States and Variants in your Main Components.

Iselin Ekornes avatar
Written by Iselin Ekornes
Updated this week

States and Variants are powerful tools within Main Components that help you design flexible, scalable, and consistent user interfaces. They let you manage interactive behaviors and purposeful design variations, all within a single, reusable component.

What are States?

States define how a component responds to user interactions, such as hovering, pressing, or focusing. These are built-in behaviors based on standard CSS pseudo-classes. States are triggered automatically by user actions, so all you need to do is define how the component looks in each state.

State Types

State

Description

Default

The component's base appearance before any interaction.

Hover

Style is applied when a user hovers over the component.

Pressed

Style shown while a component is being clicked or tapped.

Focused

Visual indicator when a component receives focus via mouse, keyboard, or touch.

Focused (keyboard)

A focus style triggered specifically via keyboard (e.g., using the tab key) to improve accessibility,

What are Variants?

Variants are alternate versions of a component that are used for different use cases, themes, or contexts. Instead of creating separate components for each design, you can house them all as Variants within a single Main Component.

Examples of Variants

Component

Variant Examples

Button

Primary, Secondary, Danger

Card

Compact, Detailed, Featured

Navbar

Light mode, Dark mode

Variants are manually defined by the designer and can be used to adapt components to brand styles or layouts.

Key Differences

States

Variants

Triggered by

User interaction or browser behavior

Design intent

Examples

Hover, Pressed, Focused

Primary, Secondary, Large, Dark Mode

Purpose

Style based on interaction

Style for different contexts

Using States and Variants Together

Combining States and Variants lets you create components that are both dynamic and adaptable. Use both to build responsive, consistent, and scalable components, without the effort of duplication.

Example: A Button Component

Variants

States

Primary

Default, Hover, Pressed, Focused

Secondary

Default, Hover, Pressed, Focused

With this setup, you get two distinct button styles, each with its own interactive behavior, all managed within one reusable component.

How to Use States

Applying a State

  1. Select the Main Component (i.e. a button or link) to which you want to apply a state.

  2. Enter the 'Edit mode' of the Main Component.

  3. Go to the styles panel.

  4. Click the States dropdown and choose the desired state (i.e., Hover, Pressed, Focused)

  5. Update the styles (i.e., change background color or add borders)

  6. Preview your project to test how the states respond.

Adding a State Transition

  1. Ensure the 'Default state' is selected.

  2. Scroll to the bottom of the style panel and find the Transition section.

  3. Clicking the '+' button.

  4. Adjusting settings such as easing, duration, and delay.

  5. Preview the project to see the transition in action.

Tip: If the transition doesn't work, check whether the properties in the target state (i.e., hover) are different from the default.

How to Use Variants

Adding or Editing a Variant

  1. Enter 'Edit mode' for the Main Component.

  2. Go to the left panel and click the '+' button to create a new variant.

  3. Give the variant a descriptive name (i.e., Secondary)

  4. Modify the component by showing/hiding layers or changing styles. Note: Adding or deleting layers can only be done in the default variant. For other variants, you need to show or hide the layers.

  5. Exit 'Edit mode' to save your new variant.

Using a Variant

  1. Add the Main Component to the canvas.

  2. Select the component and go to the styles panel.

  3. Use the variant dropdown at the top to switch between different variants of the component.

Deleting a Variant

  1. Enter 'Edit mode' and select the variant.

  2. Click the 'Delete' button.

  3. Confirm the deletion.

Best practices

  • Clear visual distinctions: Ensure there is a noticeable difference between states like hover, focus, and pressed to guide user interactions.

  • Consistency: Maintain consistent state behavior across similar components to create a uniform experience.

  • Purposeful variants: Each variant should serve a clear, distinct purpose, such as different button types or sizes.

  • Intuitive naming: Use clear and descriptive naming conventions for variants (i.e., 'Button/Primary' or 'Card/with Image') to make components easy to identify.

  • Scalability: Design with future needs in mind, planning for additional variants or states that might be required later.

  • Responsive design: Ensure states and variants are responsive across devices (desktop, mobile, tablet) for a seamless user experience.

  • Accessibility: Provide visible focus indicators for keyboard navigation and ensure all states and variants meet color contrast and text size guidelines to be accessible for all users. Learn how to optimize for accessibility in Vev.

Did this answer your question?