This guide explains how to use the fluid responsive variables feature in the WordPress Theme.json Exporter plugin.
Fluid variables in WordPress allow for responsive values that automatically scale between minimum and maximum values based on the viewport width. This eliminates the need for multiple breakpoints for many design elements.
The WordPress Theme.json Exporter plugin automatically converts Figma variables with "Desktop" and "Mobile" modes into fluid variables in the theme.json format.
-
Create a variable collection with exactly two modes:
- Name the first mode "Desktop" (for larger screens)
- Name the second mode "Mobile" (for smaller screens)
-
Create variables within this collection
- Set appropriate values for both Desktop and Mobile modes
- Values can be direct numbers, colors, or references to other variables
-
Publish your variables to make them available for export
The plugin automatically detects collections with Desktop and Mobile modes and exports them as fluid variables with the following structure:
{
"spacing": {
"base": {
"fluid": "true",
"min": "8px",
"max": "16px"
}
}
}Where:
minis the Mobile valuemaxis the Desktop valuefluid: "true"indicates this is a fluid variable (using string format for WordPress compatibility)
As of the latest update, fluid variables are exported with the fluid property as a string value ("true") rather than a boolean value (true). This change ensures compatibility with WordPress theme.json parsing.
Before:
"spacing": {
"base": {
"fluid": true,
"min": "8px",
"max": "16px"
}
}After:
"spacing": {
"base": {
"fluid": "true",
"min": "8px",
"max": "16px"
}
}The plugin handles different scenarios for fluid variables:
-
Direct values in both modes:
- Exports both values as-is with appropriate units
- For example,
8px(Mobile) and16px(Desktop)
-
Variable references in both modes:
- Exports both as CSS variable references
- For example,
var(--wp--custom--spacing--small)andvar(--wp--custom--spacing--large)
-
Mixed references and direct values:
- In this case, we prioritize the Desktop value
- No fluid scaling is applied in this scenario
-
Same value in both modes:
- If the Mobile and Desktop values are identical, the plugin exports a single value instead of a fluid object
- This optimizes the theme.json file size
When WordPress processes these fluid variables, it generates CSS similar to:
--wp--custom--spacing--base: clamp(8px, calc(8px + ((1vw - 3.2px) * 1.1429)), 16px);This CSS clamp() function automatically scales the value between:
- 8px at the smallest viewport (typically 320px)
- 16px at the largest viewport (typically 1024px)
- Values in between are calculated proportionally
Fluid variables are particularly useful for:
- Spacing values that should scale with screen size
- Typography (font sizes, line heights)
- Layout dimensions (widths, margins, paddings)
- Border radii and other visual treatments
- Use meaningful differences between Mobile and Desktop values
- Consider user experience when setting min and max values
- Use for properties that benefit from scaling - not everything needs to be fluid
- For text, pair with fluid typography in WordPress
{
"spacing": {
"base": {
"fluid": "true",
"min": "8px",
"max": "16px"
},
"medium": {
"fluid": "true",
"min": "16px",
"max": "32px"
},
"large": {
"fluid": "true",
"min": "24px",
"max": "48px"
}
}
}{
"typography": {
"fontSize": {
"small": {
"fluid": "true",
"min": "14px",
"max": "16px"
},
"medium": {
"fluid": "true",
"min": "16px",
"max": "20px"
},
"large": {
"fluid": "true",
"min": "20px",
"max": "36px"
}
}
}
}- Variables not exporting as fluid: Make sure your collection has exactly two modes named "Desktop" and "Mobile"
- Unexpected values: Check the values in each mode in Figma
- Not working in WordPress: Ensure WordPress version supports fluid variables (WordPress 6.1+)
For more information on WordPress fluid variables, see the WordPress documentation.