Set style property

style.setProperty(prop, value, options?)

Manage the CSS of a Style by setting a specific style property at the given breakpoint and pseudo-state.

Syntax

1 style.setProperty(prop: StyleProperty, value: String, options?: BreakpointAndPseudo): Promise<void>

Parameters

  • prop: StyleProperty - The property to set. See the Style Properties reference for a list of supported properties.

  • value: String | VariableReference - The value to set. You can set the value to a string or a variable reference.

  • options: BreakpointAndPseudo (optional)

    An object to set the style property at a specific breakpoint and/or pseudo-state.

    1{
    2 breakpoint?: BreakpointId
    3 pseudo?: PseudoStateKey
    4}
    • BreakpointId: Identifies the responsive breakpoint to set the style property for.

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

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

Returns

Promise<null>

A Promise that resolves to null

Example

1// Retrieve the style by name
2const retrievedStyle = await webflow.getStyleByName(styleName);
3
4// Set Style Properties
5const options: BreakpointAndPseudo = { breakpoint: "xl", pseudo: "hover" }
6await retrievedStyle?.setProperty('background-color', 'blue', options)

Try this example

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyStyleBlocksAnyAnyCanvasDesign