Badge Webflow Award Winner 2023

Guide to using Variables in Webflow

Published on 
12/10/2023
-
Amended on 
8/11/2023
Reading time: 5 min
Webflow variables
Written by
Photo of Thibaut Legrand wearing a black t-shirt Digidop

Thibaut Legrand

Webflow Developer & SEO

Explore the world of variables in Webflow to create more consistent, interactive and flexible websites.

Key points to remember

Keeping a project structured and consistent from A to Z may seem complex, but Webflow simplifies the process with a powerful tool: variables.

In this article, we'll explore in depth how Webflow variables work and how they can enhance your workflow in Webflow. Whether you're a beginner or an expert, you'll discover how variables enable you to customize your website consistently and flexibly.

I. Understanding Variable Types in Webflow

To master variables in Webflow, it's essential to understand both their function in the code and their use in the Webflow interface. Let's explore these concepts in detail.

1. Variables in HTML and CSS code

In the world of web programming, variables are elements that store reusable data and can be used to simplify code and make it more dynamic. In HTML and CSS, you may encounter variables using the following notation:

<style>
:root {
  --nom-variable: valeur;
}
</style>

In this example, --variable-name is the name of the variable, and value is the associated value. You can use this variable in your CSS by calling it this way:

<style>
sélecteur {
  propriété: var(--nom-variable);
}
</style>

Variables in code are powerful because they allow you to define values that can be reused anywhere in your CSS code. If you decide to change the value, it will automatically be updated wherever the variable is used, ensuring visual consistency.

2. Variables in Webflow

Webflow simplifies the use of variables by making them accessible in a user-friendly interface. You can think of them as parameters you define for elements of your website.

Here's how you can use variables in Webflow :

  • Color Variables: You can define a color variable for text, background, border, etc. Once defined, you can assign this variable to different elements of your site. Once defined, you can assign this variable to different elements of your site. If you decide to change the color, it will be automatically updated wherever the variable is used.
  • Size variables: Size variables allow you to set element dimensions, margins, spacing and other parameters. As with color variables, they offer enormous flexibility. Modifying a size variable will result in a uniform update of all occurrences of that variable on your site.
  • Font variables: Font variables allow you to customize the font used for titles, paragraphs, buttons, etc. Once again, modifying the font variable will automatically update all texts using this variable. Again, modifying the font variable will automatically update all texts using that variable.

Variables in Webflow work in the same way as variables in CSS code, but are simplified for user-friendly use in the design interface. You define them once, and can assign them to different elements of your site, ensuring visual consistency and simplifying the customization of your project.

Here again, Webflow proves that it's not a no-code tool, but a visual development tool!

II. Practical use of Variables

Variables in Webflow aren't just theoretical concepts. They are powerful tools for customizing and simplifying your design process.

This section explains how to create your own variables and use them in the Webflow editor for consistent, adaptive styles.

1. Customize / Create Variables

Webflow has changed the Designer's visual interface, and the new features added at Webflow Conf' 2023 are now visible.

To create variables, a new icon has appeared in the designer's left-hand panel. The label icon (below the components icon) provides access to variables. You can also use the "V" keyboard shortcut.

Once in this interface, you can view all the variables you've created, or add new ones by clicking on the"+ New Variable" button in the top right-hand corner.

The interface also features a search bar to easily find your variables.

As mentioned above, you can create variables for colors, sizes and font families.

webflow variable interface

2. Use / Login in Designer

Once you've created your variables, you can connect them to elements/styles in the Webflow Designer.

We advise you to take the time to configure all your variables before you start developing your project. Going back and forth will waste your time. This is where Design-Dev collaboration becomes even more important, to ensure that variables are created correctly and consistently.

To do this, select an element in the designer and enter the CSS parameter you wish to connect to a variable.

For example, if I want all my H2s to have a font color linked to a variable, then :

  • I've just selected my "H2" HTML semantic tag
  • I go to CSS styles "color" in my Webflow style panel
  • When I hover over the color, I click on the little purple dot
  • I select the appropriate variable

This approach is similar for other variable types (size & font family) and also for utility or custom classes (not necessarily HTML semantic tags such as: Body, H1, H2, etc.).

Once connected, if I decide to modify the property of a variable, it will change on all the classes linked to it.

Your development methodology needs to be rethought with this new functionality to create sites that are easier to manage globally.

Connecting a

III. Efficient Variable Management

Variable management is essential to keeping a web design project organized and efficient. This section will guide you through two key aspects of variable management: variable groups and links between variables.

1. Variable Groups: Organizing for Clarity

Creating variables is a great way to simplify the customization of your website, but when a project becomes complex, it's easy to get lost. To avoid this, Webflow lets you organize your variables into groups, simplifying management and access.

- Creating groups: To organize your variables into groups, start by giving the group a clear name. For example, you could have a"font-size" group containing all the font-size variables in your project. We'll have a "font-size" root and then add a "/" to specify the property. For example, you could have :

  • font-size/tiny
  • font-size/small
  • font-size/regular
  • font-size/medium
  • font-size/large

So all these variables will be in a "font-size" group. This will make it easier for you to navigate through your variables and understand their function.

- Fast access: One of the key advantages of organizing in groups is speed of access. When you're looking for a specific variable, you'll know where to find it without wasting time browsing your entire list of variables. This is as true in the Variable Panel as it is when you connect a variable to the Designer.

2. Variable Links: Advanced Customization

As you become more advanced in the use of variables, you can begin to explore the links between variables. This feature allows you to add an advanced layer of customization to your website.

- Understanding Variable Links: Variable links allow you toassociate one variable with another. In the variable management interface, you can connect one variable to another (only of the same type). For example, I can create a "heading-size/h4" variable and connect it to the value of my "font-size/xxlarge" variable.

So if I change the value of my "font-size/xxlarge" variable, it will also change the value of my "heading-size/h4" variable (since they're connected).

Linking variables in webflow

- Precise customization: Links between variables offer precise customization of your site. You can create relationships between different properties and variables to ensure total consistency, even when making complex modifications.

Effective variable management is essential to make the most of these powerful customization tools. By organizing your variables into groups and understanding the links between variables, you ensure that your web design project remains clear, accessible and flexible for advanced customization.

IV. Variables in Animations and Interactions

Variables are not limited to the static design of your website. They can also be brought into play in dynamic interactions, adding an interactive and engaging dimension to your site.

So how does it work?

In your Webflow interactions, you may have seen a new element appear (Global Variables > Set variable value). It's this element that lets you play with variable properties.

I select one of my variables and can change its value. For example, if the value of my "color-dark-mode/heading" variable was originally yellow, I can change it to blue.

Scroll interactions to change the color of my heading variable from yellow to blue

What can I do?

You can, for example, change the colors of variables when a button is clicked, when a section is scrolled, when elements appear and many other possibilities. You can also do all this with size and font variables. With this, you can create a dark & light mode on your website quite easily.

In short, let your imagination run wild!

Conclusion: Create more efficient websites with Webflow Variables

Variables in Webflow are a powerful resource for web developers. By understanding variable types, their practical use, efficient management and their role in animations, you can create more consistent, flexible and visually appealing websites.

Feel free to experiment with variables to improve your next web project!

Flomodia by Digidop
Coudac project by Digidop
project Heka by DigidopFlaw by project DigidopMorfo project by Digidop