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
      • Get variable mode
      • Get variable modes
      • Set variable mode
      • Set variable modes
      • Remove variable mode
      • Remove variable modes
      • Remove all variable modes
  • Components
  • 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
  • style.setVariableMode(collection, mode, options?)
  • Syntax
  • Parameters
  • Returns
StylesManaging Variable Modes

Set variable mode on a style

Was this page helpful?
Previous

Set variable modes on a style

Next
Built with

style.setVariableMode(collection, mode, options?)

Apply a variable mode to a style. Each variable mode belongs to a variable collection. To apply a variable mode, you must provide the variable collection that belongs to the variable mode.


Syntax

1 style.setVariableMode(
2 collection: {{VARIABLE_COLLECTION}},
3 mode: {{VARIABLE_MODE}},
4 options?: {
5 breakpointId?: {{BREAKPOINT_ID}},
6 pseudoStateKey?: {{PSEUDO_STATE_KEY}}
7 }
8 ): Promise<null>;

Parameters

  • collection: VariableCollection - The variable collection that belongs to the variable mode.

  • mode: VariableMode - The variable mode to set.

  • options?: BreakpointAndPseudo - An object that lets you filter properties by breakpoint and/or pseudo-state. (Optional)

    • BreakpointId: Identifies the responsive breakpoint to get styles for.

      1type BreakpointId = "xxl" | "xl" | "large" | "main" | "medium" | "small" | "tiny"
    • PseudoStateKey: Specifies a CSS pseudo-class to get styles for.

      1type PseudoStateKey = "noPseudo" | "nth-child(odd)" | "nth-child(even)" |
      2 "first-child" | "last-child" | "hover" | "active" |
      3 "visited" | "focus" | "focus-visible" | "focus-within" |
      4 "placeholder" | "empty" | "before" | "after"

Returns

Promise<null>

A Promise that resolves to null.

Example

1// Get Selected Element
2const selectedElement = await webflow.getSelectedElement()
3
4 if (selectedElement?.styles) {
5 // Get Styles
6 const styles = await selectedElement.getStyles()
7 const primaryStyle = styles[0] // Get the primary style
8
9 // Get Variable Collection
10 const variableCollection = await webflow.getDefaultVariableCollection()
11 const variableModes = await variableCollection?.getAllVariableModes()
12 const variableMode = variableModes[0]
13
14 // Set Variable Mode
15 if (primaryStyle && variableCollection) {
16 await primaryStyle.setVariableMode(variableCollection, variableMode)
17 console.log('Variable mode set successfully')
18 }
19}

Try this example

Designer ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyStyleBlocksAnyAnyCanvasDesign