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:

AreaProperties
Margin and paddingTop, bottom, left, right
PositionTop, bottom, left, right
Column and row gapsDisplay settings, Quick Stack
DimensionsHeight, width (including min and max)
GridColumn and row sizes
TypographyFont size, line height, letter spacing
BorderRadius, width
Filter and backdrop filterBlur radius

Syntax

1collection.createSizeVariable(
2 name: string,
3 value: {{SIZE_VALUE}} | {{VARIABLE_REFERENCE}} | {{CUSTOM_VALUE}},
4 options?: {
5 mode?: {{VARIABLE_MODE}}
6 }
7): Promise<SizeVariable>

Parameters

  • name : string - Name of the variable

  • value:

    • SizeValue - Object with the unit and value of the size. {unit: SizeUnit, value: number}
      • SizeUnit See the accordion below for the list of supported units.

        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;
    • SizeVariable - A reference to another size variable
    • CustomValue - A custom value for the variable
  • options: object - Optional parameters for the variable.

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)

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyVariablesAnyMainCanvasDesign