For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Resources
Get started
ReferenceGuidesExamplesChangelog
ReferenceGuidesExamplesChangelog
  • Designer API
    • Introduction
    • Getting Started
    • Webflow CLI
    • Error Handling
    • App Modes
  • Elements
    • Creating & Retrieving Elements
    • Element Properties & Methods
    • Element Types & Methods
  • Styles
    • Managing Style Properties
    • Managing Variable Modes
  • Components
      • Create a component instance
      • Open a component canvas
      • Set the selected variant
      • Select a component
      • Exit out of a component
      • Get root element
      • Get component name
      • Get component
      • Set component name
      • Get component settings
      • Set component settings
      • Get props
      • Create a prop
      • Create multiple props
      • Get a prop
      • Get a prop by name
      • Set prop settings
      • Remove a prop
  • Variables & Collections
    • Variable Collections
    • Variables
    • Variable Modes
  • Assets
  • Pages & Folders
  • Utilities
    • User Events & Notifications
    • App Intents & Connections
  • Additional Resources
    • API Playground
    • FAQs
LogoLogo
Resources
Get started
On this page
  • component.setSelectedVariant(variant)
  • Syntax
  • Returns
  • Example
  • Designer Ability
ComponentsManaging Components

Set the selected variant (Beta)

Was this page helpful?
Previous

Select a component

Next
Built with

component.setSelectedVariant(variant)

Selects the specified variant of a selected component when the component canvas is open.

To use this method, ensure that the component canvas is open and a variant is currently selected. Then, to specify the variant to select, pass one of these parameters:

  • The ID of the variant as a string, as in component.setSelectedVariant('secondary-hero')
  • The ID of the variant as the id field in an object, as in component.setSelectedVariant({ id: 'secondary-hero' })
  • The name of the variant as the name field in an object, as in component.setSelectedVariant({ name: 'Secondary Hero' })
Beta

These methods are in public beta and may change with future releases.

Syntax

1interface SetSelectedVariantByName {
2 name: string;
3}
4interface SetSelectedVariantById {
5 id: string;
6}
7
8type SetSelectedVariantOptions = SetSelectedVariantByName | SetSelectedVariantById;
9
10setSelectedVariant(options: SetSelectedVariantOptions | string): Promise<void>;

Returns

Promise<void>

A promise that resolves when the specified variant is selected.

Example

1// Select component
2const heroComponent = await webflow.getComponentByName('Hero')
3
4// Select variant by name
5await heroComponent.setSelectedVariant({ name: 'Secondary Hero' });
6
7// Select variant by ID (object form)
8await heroComponent.setSelectedVariant({ id: 'secondary-hero' });
9
10// Select variant by ID (string shorthand)
11await heroComponent.setSelectedVariant('secondary-hero');
12
13// Select the base variant
14await heroComponent.setSelectedVariant({ id: 'base' });
15await heroComponent.setSelectedVariant('base');

Try this example


Designer Ability

Checks for authorization only

Designer AbilityPermissionLocaleBranchWorkflowSitemode
canAccessCanvasanyanyanyanyany