Variables
Variables are reusable design tokens that let you define and manage values across your Webflow projects. They enable you to create a single source of truth for common values like colors, spacing, and typography. When you update a variable’s value, that change automatically propagates everywhere the variable is used, making it easy to maintain consistency and make global design updates.
Assign variables to any compatible style property. For example, you can use color variables for background colors, size variables for padding and margins, or font variables for typography. When the variable’s value changes, all style properties using that variable will automatically update, providing a powerful way to maintain design consistency and make global updates efficiently.
Variables
Webflow currently supports 5 types of variables:
- Size
- Color
- Font
- Percentage
- Number
Creating a variable
Create variables using the appropriate creation function for each variable type. Each variable requires a unique name within its collection. The creation functions follow this pattern:
General Syntax
collection.createXXXVariable(variable-name, variable-value);
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 collection.createColorVariable(“primary”, “red”); RGB Hex collection.createColorVariable(“primary”, “#ffcc11”); RGBA Hex collection.createColorVariable(“primary”, “#fffcc11”); |
Size | Object in the following format: { unit: “px” | “rem” | “em” | “vw” | “vh” | “svh” | “svw” | “ch” value: number } | collection.createSizeVariable(“defaultLength”, { unit: “px”, value: 50 }); |
Number & Percentage | Number value between 0 and 100 | collection.createPercentageVariable(“opacity”, 50); collection.createNumberVariable(“scale”, 1.5); |
FontFamily | String of the font family name (e.g., “Verdana”) | collection.createFontFamilyVariable(“defaultFont”, “Verdana”); |
Selecting a variable
Select variables from their Collection by their name or ID.
Editing a variable
Renaming and setting new values on a variable.
Renaming a variable
Variables in Webflow can be renamed for better clarity or organization. After you’ve successfully renamed a variable, all instances where this variable is used will automatically reference the new name.
Setting a variable value
A variable type (size, percentage, number, color, font family) in Webflow cannot be changed. However, its value can be updated. The format for updating the value is consistent with its initial declaration.
Applying variables to styles
After defining your variables, you can incorporate them into your styles. To do this, simply use the variable as the property value in the style you’re customizing.
Applying a Variable as an Alias
When you assign a variable to reference another, the second variable effectively becomes an alias of the first. This results in the second variable mirroring the value of the first one they are both linked to. Any changes made to the value of the first variable will be automatically reflected in the second, maintaining their synchronization. It’s essential that both variables are of the same type for alias references to function correctly.
In the below example, both the variables are of type ColorVariable.
Removing a variable
Deleting a Variable
Variables in Webflow can also be deleted. When a variable is removed, it undergoes a “soft delete” process, similar to the approach taken in the Webflow user interface.