variable.set(value)

Set the value of the selected variable.

Parameters

Type Accepted Formats for Value Examples
Color Strings of one of three formats:
- Color name
- Color rgb hex value
- Color rgba hex value
Color Name
variable.set(“primary”, “red”);

RGB Hex
variable.set(“primary”, “#ffcc11”);

RGBA Hex
variable.set(“primary”, “#fffcc11”);
Size Object in the following format:
{ unit: “px” | “rem” | “em” | “vw” | “vh” | “svh” | “svw” | “ch” value: number }
variable.set(“defaultLength”, { unit: “px”, value: 50 });
FontFamily String of the font name (e.g., “Verdana”) variable.set(“defaultFont”, “Verdana”);

Returns

Promise<null>

A Promise that resolves to null

Example

1// Get Collection
2const collection = await webflow.getDefaultVariableCollection()
3
4// Get Variable
5const variable = await collection?.getVariableByName("MyColorVariable")
6
7// Check Variable type and set color
8if (variable?.type === "Color") await variable.set("#fffcc11");

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyVariablesAnyMainCanvasDesign