Create size variable

collection.createSizeVariable(name, value)

Create a Size variable with a name for the variable, and size value.

Once created, you can set size variables for:

  • Margin and padding — top, bottom, left, right
  • Position — top, bottom, left, right
  • Column and row gaps for display settings and Quick Stack
  • Height and width dimensions (including min and max)
  • Grid column and row sizes
  • Typography — font size, line height, letter spacing
  • Border radius and width
  • Filter and backdrop filter blur radius

Syntax

1collection.createSizeVariable(name: string, value: SizeValue | SizeVariable | CustomValue): Promise<SizeVariable>

Absolute Units

UnitNameDescriptionExample Usage
pxPixelsAbsolute unit, 1px equals one pixel on the screenfont-size: 16px;

Relative Units

UnitNameDescriptionExample Usage
emElement-relative EmRelative to parent element’s font size (2em = 2× parent font)padding: 1.5em;
remRoot EmRelative to root element’s font sizemargin: 2rem;
chCharacter UnitsRelative to width of ‘0’ (zero) characterwidth: 20ch;

Viewport-based Units

UnitNameDescriptionExample Usage
vhViewport Height1% of viewport heightheight: 50vh;
vwViewport Width1% of viewport widthwidth: 80vw;
vminViewport Minimum1% of viewport’s smaller dimensionmargin: 2vmin;
vmaxViewport Maximum1% of viewport’s larger dimensionmargin: 2vmax;

Dynamic Viewport Units

UnitNameDescriptionExample Usage
dvhDynamic Viewport HeightAdjusts to viewport height changes (mobile browsers)min-height: 100dvh;
dvwDynamic Viewport WidthAdjusts to viewport width changesmax-width: 50dvw;
svhSmall Viewport HeightViewport height for small screensheight: 60svh;
svwSmall Viewport WidthViewport width for small screenswidth: 40svw;
lvhLarge Viewport HeightViewport height for large screensheight: 75lvh;
lvwLarge Viewport WidthViewport width for large screenswidth: 100lvw;

Parameters

  • name : string - Name of the variable
  • value: SizeValue | SizeVariable | CustomValue - Object with the unit and value of the size. {unit: SizeUnit, value: number} Additionally, you can pass a SizeVariable to create a referenced variable or CustomValue to create a variable with a custom value.
    • SizeUnit : string - Any of the following units "px" | "em" | "rem" | "vh" | "vw" | "dvh" | "dvw" | "lvh" | "lvw" | "svh" | "svw" | "vmax" | "vmin" | "ch"

Returns

Promise<SizeVariable>

A Promise that resolves to a SizeVariable object

Example

1// Get Collection
2const collection = await webflow.getDefaultVariableCollection()
3
4// Create Size Variable with a Size Value
5const mySizeVariable = await collection?.createSizeVariable("Defualt Padding", { unit: "px", value: 50 })
6console.log(mySizeVariable)
7
8// Create a Size Variable with a Custom Value
9const myCustomSizeVariable = await collection?.createSizeVariable("h1-font-size", {
10 type: "custom",
11 value: "clamp(1rem, 2vw, 2rem)",
12})
13console.log(myCustomSizeVariable)

Try this example

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyVariablesAnyMainCanvasDesign