bricks_create_global_variable

Phase 2BeginnerComplexity: 3/10
Create a CSS custom property variable

Overview

Creates a new global CSS custom property (variable) in the Bricks design system. The variable is stored as var(--name) and becomes available throughout the entire site for use in element settings, global classes, and theme styles.

If the specified category does not exist, it is automatically created. This is the single-variable creation tool — for creating multiple variables at once (e.g., a full spacing scale), use bricks_create_variables_batch instead.

Key Features

Auto-Category Creation
If you specify a category name that does not exist yet, the tool automatically creates that category before assigning the variable to it.
Clean Name Handling
You provide just the name (e.g., "spacing-sm") without the var() or -- prefix. The tool handles the CSS custom property syntax internally.
Any CSS Value
Accepts any valid CSS value — pixels, rems, percentages, hex colors, calc() expressions, or other CSS functions.
Immediate Availability
Once created, the variable is immediately available as var(--name) in all Bricks elements, global classes, and theme style settings.

When to Use

Adding a single design token to the system (e.g., a new border-radius or color variable)
Creating a variable during a quick design tweak or one-off addition
Phase 2 of a website build — setting up the design system one variable at a time
When you need to create a variable and auto-create its category simultaneously
Prerequisites
Bricks Builder must be active. The variable name must not conflict with an existing variable name. No category needs to exist beforehand — it is created automatically if specified.

When NOT to Use

When creating 3 or more variables at once — use bricks_create_variables_batch for efficiency
When you need to update an existing variable — use bricks_update_global_variable instead
When you just need to read existing variables — use bricks_get_global_variables

Parameters

3 Total Parameters2 Required1 Optional
namestringREQUIRED
Variable name without var() or -- prefix. For example, "spacing-sm" will be stored and referenced as var(--spacing-sm). Use kebab-case naming convention.
valuestringREQUIRED
Any valid CSS value. Examples: "8px", "0.5rem", "#1a3a5c", "1.5", "calc(100% - 40px)". Units are required where applicable.
categorystringoptional
Category name for organizing the variable in the Bricks UI. Created automatically if it does not exist. Common categories: "Spacing", "Colors", "Typography", "Sizing", "Borders".

Code Examples

Create a Spacing Variable

Add a single spacing token to the design system.

JSON
bricks_create_global_variable({
  name: "spacing-lg",
  value: "24px",
  category: "Spacing"
})
Response
{"success": true, "data": {"id": "v1a2b3", "name": "spacing-lg", "value": "24px", "category": "cat_spacing"}}

Create a Color Variable

Add a custom color token for reuse across the site.

JSON
bricks_create_global_variable({
  name: "color-accent-light",
  value: "#e8d4a0",
  category: "Colors"
})
Response
{"success": true, "data": {"id": "v4d5e6", "name": "color-accent-light", "value": "#e8d4a0", "category": "cat_colors"}}

Create a Border Radius Variable

Define a reusable border-radius value for cards and buttons.

JSON
bricks_create_global_variable({
  name: "radius-md",
  value: "12px",
  category: "Borders"
})
Response
{"success": true, "data": {"id": "v7f8g9", "name": "radius-md", "value": "12px", "category": "cat_borders"}}

Use the Variable in an Element

After creating a spacing variable, reference it in element settings instead of hardcoding values.

JSON
// In element settings, reference the variable:
{
  "_padding": { "top": "var(--spacing-lg)", "bottom": "var(--spacing-lg)" },
  "_gap": "var(--spacing-md)"
}
Response
// Renders as padding: 24px (top/bottom) and gap: 16px

Common Mistakes

Including the var() or -- prefix in the name parameter.
Provide just the plain name without any CSS syntax. The tool adds the var(--) wrapper internally.
Wrong
bricks_create_global_variable({
  name: "var(--spacing-sm)",
  value: "8px"
})
Correct
bricks_create_global_variable({
  name: "spacing-sm",
  value: "8px"
})
Using this tool to create the entire spacing scale one variable at a time, wasting API calls.
For 3 or more variables, use bricks_create_variables_batch which creates up to 50 variables in a single API call.
Wrong
// 9 separate API calls for the spacing scale
bricks_create_global_variable({ name: "spacing-xs", value: "4px", category: "Spacing" })
bricks_create_global_variable({ name: "spacing-sm", value: "8px", category: "Spacing" })
bricks_create_global_variable({ name: "spacing-md", value: "16px", category: "Spacing" })
// ... 6 more calls
Correct
// 1 API call for the entire spacing scale
bricks_create_variables_batch({ variables: [
  { name: "spacing-xs", value: "4px", category: "Spacing" },
  { name: "spacing-sm", value: "8px", category: "Spacing" },
  { name: "spacing-md", value: "16px", category: "Spacing" },
  // ... all 9 values
] })
Skipping spacing variables during Phase 2 — agents consistently forget this step, causing inconsistent layouts with hardcoded pixel values everywhere.
ALWAYS create the full spacing scale (xs=4px through 5xl=128px) in Phase 2. Then reference var(--spacing-lg) instead of hardcoded "24" in all element settings and global classes.
Wrong
// Hardcoded spacing everywhere
{ "_padding": { "top": "24", "bottom": "24" }, "_gap": "16" }
Correct
// Reference spacing variables for consistency
{ "_padding": { "top": "var(--spacing-lg)", "bottom": "var(--spacing-lg)" }, "_gap": "var(--spacing-md)" }

Tips & Warnings

Tips & Warnings

Naming convention: Use kebab-case with a category prefix: spacing-sm, color-primary-light, radius-lg, shadow-card. This makes variables easy to discover in the Bricks UI.

Mandatory spacing scale: Every site MUST have the full spacing scale: xs=4px, sm=8px, md=16px, lg=24px, xl=32px, 2xl=48px, 3xl=64px, 4xl=96px, 5xl=128px. Without this, layouts become inconsistent. Use bricks_create_variables_batch for the full scale.

Prefer batch for multiple variables: This tool is ideal for 1-2 variables. For 3+, always use bricks_create_variables_batch.

Return Values

FieldTypeDescription
successbooleanWhether the variable was created successfully.
data.idstringThe unique ID assigned to the new variable. Use this ID for subsequent update or delete operations.
data.namestringThe variable name as stored (without var() or -- prefix).
data.valuestringThe CSS value assigned to the variable.
data.categorystringThe category ID the variable belongs to, if a category was specified.

Related Tools

Technical Details

Tool ID
bricks_create_global_variable
API Endpoint
/bricks-mcp/v1/design-system/variables
HTTP Method
POST
Namespace
design-system
Source File
design-system/variables.ts
Version
1.0
Min Bricks Version
1.9
Requires Auth
Yes

Changelog

v1.0
Initial release
20250101