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
      • Get all components
      • Get component by name
      • Get component by ID
      • Search for components
      • Get the selected component
      • Get all variants of a component
      • Get selected variant
      • Get a variant by ID
      • Create a variant
      • Set variant settings
      • Reorder variants
      • Delete a variant
      • Get component instance count
      • Create a component
      • Delete a component
  • 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.createVariant(options)
  • component.createVariant(options, sourceVariantId)
  • Syntax
  • Parameters
  • Returns
  • Example
  • Designer Ability
ComponentsCreating & Retrieving Components

Create a variant (Beta)

Was this page helpful?
Previous

Set variant settings (Beta)

Next
Built with

component.createVariant(options)

component.createVariant(options, sourceVariantId)

Creates a variant of an existing component or duplicates an existing variant.

If a variant with the given name already exists, the name is automatically incremented (for example, 'Variant' becomes 'Variant 2').

Beta

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

Syntax

1interface CreateVariantOptions {
2 /** The name for the new variant (required) */
3 name: string;
4 /** Whether to select this variant after creation (optional, defaults to false) */
5 isSelected?: boolean;
6}

To create a variant, pass the options for the variant, including its name and whether to select it automatically:

1component.createVariant(options: CreateVariantOptions): Promise<Variant>

To duplicate an existing variant, add the ID of the variant to duplicate as the second parameter:

1component.createVariant(options: CreateVariantOptions, sourceVariantId: string): Promise<Variant>

Parameters

  • options : CreateVariantOptions — An object specifying the new variant’s settings:

    • name: string — The name for the new variant.
    • isSelected: Boolean — (optional) Whether to select this variant immediately after creation. Defaults to false.
  • sourceVariantId: string — The ID of the variant to duplicate.

Returns

Promise<Variant>

A Promise that resolves to the newly created Variant object.

PropertyTypeDescription
idstringThe unique identifier of the new variant.
namestringThe name of the new variant (may differ if auto-incremented).
isSelectedbooleanWhether this variant is currently selected in the Designer.

Example

Create a variant:

1const component = await webflow.getCurrentComponent()
2
3if (component) {
4 // Create a variant and select it immediately
5 const variant = await component.createVariant({
6 name: 'Secondary Hero',
7 isSelected: true,
8 })
9 console.log(variant)
10 // { id: 'variant-123', name: 'Secondary Hero', isSelected: true }
11
12 // Name conflicts auto-increment
13 const variant2 = await component.createVariant({ name: 'Secondary Hero' })
14 console.log(variant2.name) // 'Secondary Hero 2'
15}
16
17// Name auto-increments on conflict
18const variant2 = await component.createVariant({ name: 'Secondary Hero' });
19console.log(variant2.name); // 'Secondary Hero 2'

Duplicate a variant:

1const component = await webflow.getCurrentComponent()
2
3if (component) {
4 // Get the selected variant or the base variant as default
5 const selectedVariant = await component.getSelectedVariant()
6
7 // Duplicate the selected variant
8 const duplicateVariant = await component.createVariant({
9 name: 'Duplicate of Secondary Hero',
10 isSelected: true,
11 }, selectedVariant.id)
12 console.log(duplicateVariant.name) // 'Duplicate of Secondary Hero'
13}

Try this example

Designer Ability

Designer AbilityPermissionLocaleBranchWorkflowSitemode
canModifyComponentsanyanyanyCanvasDesign