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
  • Components
  • Variables & Collections
    • Variable Collections
    • Variables
        • Create number variable
        • Create color variable
        • Create font family variable
        • Create size variable
        • Create percentage variable
        • Get all variables
        • Get variable by name
        • Get variable by ID
    • Variable Modes
  • Assets
  • Pages & Folders
  • Utilities
    • User Events & Notifications
    • App Intents & Connections
  • Additional Resources
    • API Playground
    • FAQs
LogoLogo
Resources
Get started
On this page
  • collection.createSizeVariable(name, value)
  • Syntax
  • Parameters
  • Returns
  • Example
  • Designer Ability
Variables & CollectionsVariablesCreating & Retrieving Variables

Create size variable

Was this page helpful?
Previous

Create percentage variable

Next
Built with

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.

        Size 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.

    • mode: VariableMode - The variable mode object. Get the variable mode by using the collection.getVariableModeByName() method.

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