Design Variables

Design variables are CSS custom properties that control the visual appearance of your site. This guide covers using design variables in components and defining new variables.

What are Design Variables?

Design variables are named CSS custom properties defined at the platform level with optional site-level overrides:

:root {

  --color-primary: #3b82f6;

  --spacing-md: 16px;

  --font-size-lg: 18px;

}

Using Design Variables in Components

Reference design variables in your component.css:

.hero {

  background-color: var(--color-primary);

  padding: var(--spacing-2xl);

  font-size: var(--font-size-xl);

}

 

.hero h1 {

  color: var(--color-text);

  margin-bottom: var(--spacing-md);

}

Syntax

property: var(--variable-name);

Fallback Values

Provide fallback values for variables that might not be defined:

.card {

  border-radius: var(--border-radius-md, 8px);

  box-shadow: var(--shadow-md, 0 4px 6px rgba(0,0,0,0.1));

}

Syntax: var(--variable-name, fallback-value)

Variable Categories

Variables are organized into categories:

Colors

.element {

  color: var(--color-text);

  background-color: var(--color-background);

  border-color: var(--color-border);

}

Available color variables:

  • --color-primary: Primary brand color
  • --color-secondary: Secondary brand color
  • --color-background: Page background
  • --color-text: Primary text color
  • --color-text-muted: Secondary text color
  • --color-border: Border color
  • --color-success: Success state
  • --color-warning: Warning state
  • --color-error: Error state

Typography

.text {

  font-family: var(--font-family-base);

  font-size: var(--font-size-base);

  font-weight: var(--font-weight-normal);

  line-height: var(--line-height-base);

}

Available typography variables:

  • --font-family-base: Body text font
  • --font-family-heading: Heading font
  • --font-size-base: Base font size (16px)
  • --font-size-sm: Small text (14px)
  • --font-size-lg: Large text (18px)
  • --font-size-xl: Extra large text (20px)
  • --font-weight-normal: Normal weight (400)
  • --font-weight-medium: Medium weight (500)
  • --font-weight-bold: Bold weight (700)
  • --line-height-base: Base line height (1.5)
  • --line-height-heading: Heading line height (1.2)

Spacing

.container {

  margin: var(--spacing-lg);

  padding: var(--spacing-md);

  gap: var(--spacing-sm);

}

Available spacing variables:

  • --spacing-xs: 4px
  • --spacing-sm: 8px
  • --spacing-md: 16px
  • --spacing-lg: 24px
  • --spacing-xl: 32px
  • --spacing-2xl: 48px

Layout

.container {

  max-width: var(--container-max-width);

  padding: var(--container-padding);

}

 

.grid {

  display: grid;

  grid-template-columns: repeat(var(--grid-columns), 1fr);

  gap: var(--grid-gap);

}

Available layout variables:

  • --container-max-width: Maximum content width (1280px)
  • --container-padding: Container padding (16px)
  • --grid-gap: Grid gap (16px)
  • --grid-columns: Grid columns (12)

Borders

.card {

  border: var(--border-width) solid var(--color-border);

  border-radius: var(--border-radius-md);

}

Available border variables:

  • --border-width: Default border width (1px)
  • --border-radius-sm: Small radius (4px)
  • --border-radius-md: Medium radius (8px)
  • --border-radius-lg: Large radius (12px)
  • --border-radius-full: Full radius (9999px)

Shadows

.card {

  box-shadow: var(--shadow-md);

}

 

.elevated {

  box-shadow: var(--shadow-lg);

}

Available shadow variables:

  • --shadow-sm: Small shadow
  • --shadow-md: Medium shadow
  • --shadow-lg: Large shadow

Components

Every built-in component (button, teaser, title, rich-text, site-navigation, page-list, percentage-bar, image, comments, container, table) exposes its per-component CSS custom properties as platform design variables in the Components category. Editing them in Platform → Variables or Site → Theme restyles every instance of that component site-wide — colours, padding, radii, typography, hover states, etc. Values default to the concrete CSS defaults, or to a var(--…) chain that lets the component pick up a global colour (e.g. --button-primary-bg defaults to var(--color-primary, #0066cc) so overriding --color-primary is usually enough).

Component variables are named --<component>-<property> (e.g. --teaser-padding, --button-primary-hover-bg, --percentage-bar-fg) and are searchable from the Design Variables Reference.

Defining New Variables

Components can define new design variables in variables.json:

{

  "variables": [

    {

      "name": "--hero-min-height",

      "category": "layout",

      "description": "Minimum height of hero banner",

      "defaultValue": "400px"

    },

    {

      "name": "--hero-overlay-opacity",

      "category": "other",

      "description": "Opacity of hero image overlay",

      "defaultValue": "0.3"

    }

  ]

}

Variable Definition Schema

Each variable definition requires:

  • name: Variable name (must start with --)
  • category: One of color, spacing, typography, layout, border, shadow, component, other
  • description: Human-readable description
  • defaultValue: Default CSS value

Variable Naming Conventions

  • Start with --: All CSS custom properties start with --
  • Use kebab-case: --hero-min-height, not --heroMinHeight
  • Be descriptive: --card-padding, not --cp
  • Include component name: --hero-overlay-opacity, not --overlay-opacity

Using Custom Variables

After defining variables, use them in your component CSS:

.hero {

  min-height: var(--hero-min-height);

  position: relative;

}

 

.hero::after {

  content: '';

  position: absolute;

  inset: 0;

  background: rgba(0, 0, 0, var(--hero-overlay-opacity));

}

Variable Registry

All design variables (platform defaults and component-defined) are stored in the Variable Registry.

Viewing the Variable Registry

To view all available variables:

  1. Navigate to Settings → Variables
  2. Browse variables by category
  3. View descriptions and default values

Variable Merging

When a component defines a variable that already exists:

  • Platform default is preserved: The existing default value is not overwritten
  • Component can use the variable: The component can reference the existing variable
  • Sites can override: Sites can override the variable value

Platform Defaults vs Site Overrides

Platform Defaults

Platform defaults are defined at the platform level and apply to all sites:

:root {

  --color-primary: #3b82f6;

  --spacing-md: 16px;

}

Site Overrides

Sites can override platform defaults:

:root {

  --color-primary: #ff6b6b; /* Site override */

  --spacing-md: 16px; /* Platform default (not overridden) */

}

Resolution

When rendering a page:

  1. Load platform defaults from Variable Registry
  2. Load site overrides from Site Theme
  3. Merge: site overrides take precedence
  4. Inject resolved variables into page <head>

Responsive Design with Variables

Use variables with media queries for responsive design:

.hero {

  padding: var(--spacing-md);

}

 

@media (min-width: 768px) {

  .hero {

    padding: var(--spacing-xl);

  }

}

Breakpoint Variables

The platform provides breakpoint variables:

@media (min-width: var(--bp-tablet)) {

  .container {

    max-width: 768px;

  }

}

 

@media (min-width: var(--bp-small-desktop)) {

  .container {

    max-width: 1024px;

  }

}

 

@media (min-width: var(--bp-desktop)) {

  .container {

    max-width: 1280px;

  }

}

Available breakpoint variables:

  • --bp-tablet: 768px (default)
  • --bp-small-desktop: 1024px (default)
  • --bp-desktop: 1280px (default)

Sites can override breakpoint values in their theme settings.

Best Practices

When to Use Variables

Use variables for:

  • Colors that should match the site theme
  • Spacing that should be consistent across components
  • Typography that should match the site's font settings
  • Layout dimensions that should be configurable

Don't use variables for:

  • Component-specific values that shouldn't be themed
  • Values that are intrinsic to the component's design
  • One-off values that won't be reused

Variable Naming

  • Be specific: --card-border-radius, not --radius
  • Include context: --hero-min-height, not --min-height
  • Use semantic names: --color-primary, not --color-blue
  • Follow conventions: Use existing variable patterns

Fallback Values

Always provide fallback values for custom variables:

.hero {

  min-height: var(--hero-min-height, 400px);

}

This ensures the component works even if the variable isn't defined.

Documentation

Document your custom variables:

  • Provide clear descriptions in variables.json
  • Explain when and how to use each variable
  • Include example values in descriptions

Example: Component with Custom Variables

variables.json

{

  "variables": [

    {

      "name": "--card-padding",

      "category": "spacing",

      "description": "Padding inside card components",

      "defaultValue": "24px"

    },

    {

      "name": "--card-border-radius",

      "category": "border",

      "description": "Border radius for card components",

      "defaultValue": "12px"

    },

    {

      "name": "--card-shadow",

      "category": "shadow",

      "description": "Box shadow for card components",

      "defaultValue": "0 4px 6px rgba(0, 0, 0, 0.1)"

    }

  ]

}

component.css

.card {

  padding: var(--card-padding, 24px);

  border-radius: var(--card-border-radius, 12px);

  box-shadow: var(--card-shadow, 0 4px 6px rgba(0, 0, 0, 0.1));

  background-color: var(--color-background);

  border: var(--border-width) solid var(--color-border);

}

 

.card-title {

  font-family: var(--font-family-heading);

  font-size: var(--font-size-xl);

  font-weight: var(--font-weight-bold);

  color: var(--color-text);

  margin-bottom: var(--spacing-md);

}

 

.card-content {

  font-family: var(--font-family-base);

  font-size: var(--font-size-base);

  line-height: var(--line-height-base);

  color: var(--color-text);

}

Testing Variables

Test with Different Themes

Test your component with different variable values:

  1. Create a test site
  2. Override variables in the site theme
  3. Publish a page with your component
  4. Verify the component adapts correctly

Test Fallbacks

Test that fallback values work:

  1. Remove variable definitions
  2. Verify the component still renders correctly
  3. Check that fallback values are applied

Troubleshooting

Variable Not Applied

If a variable isn't being applied:

  1. Check variable name: Ensure the name matches exactly (case-sensitive)
  2. Check syntax: Verify var(--variable-name) syntax is correct
  3. Check specificity: Ensure CSS specificity isn't overriding the variable
  4. Rebuild site: Perform a site rebuild to apply variable changes

Variable Value Wrong

If a variable has the wrong value:

  1. Check site overrides: Verify the site theme settings
  2. Check platform defaults: Review the Variable Registry
  3. Check component definition: Verify variables.json is correct
  4. Clear cache: Clear browser and CDN cache

Related Topics