> For the complete documentation index, see [llms.txt](https://kb.craftformswp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kb.craftformswp.com/documentation/form-building/form-styles/css-variables-and-classes.md).

# CSS Variables and Classes

### Overview

Every value in [Form Styles](https://kb.craftformswp.com/documentation/form-building/form-styles.md) is a CSS variable named `--cf-form-*`. You can set them yourself, without the settings page: in your theme or child theme, in a page builder's custom CSS, on a static site that shows an embedded form, or in code. Point a few of them at your own design tokens and every form follows, in every form style. No DevTools, no CraftForms class names, no `!important`.

This page is for developers and for anyone styling forms outside WordPress: every variable with its default, the stable class names, how embedded forms on other websites pick the variables up, and the filters for themes and frameworks.

Nothing here is required. A variable you don't set keeps the form style's own value, so a form looks exactly as before until you set one.

### Quick start

```css
/* Your theme or child theme, Bricks / Core Framework custom CSS,
   Customizer → Additional CSS, or the stylesheet of the website a form is embedded on */
:root {
  --cf-form-accent: var(--primary);          /* your brand colour */
  --cf-form-border: var(--border-color);
  --cf-form-radius: var(--radius-s);
  --cf-form-input-padding: var(--space-xs);
  --cf-form-gap: var(--space-m);
  --cf-form-font-family: var(--font-body);
}
```

Replace the right-hand names with the variables your design system defines (they differ between Core Framework, Automatic.css, Bricks' Style Manager and others), or write plain values (`#0f766e`, `6px`).

### How it works

* Each form style (Default, Modern, Builderius CSS, Unstyled) reads the same `--cf-form-*` variables, with its own value as the fallback: `var(--cf-form-border, #c0c4c9)`. No CraftForms stylesheet sets one, so whatever you set is what's used.
* Set them wherever a form inherits from: `:root` for the whole site, a wrapper for one section, or one form's class. The nearest one wins, as with any CSS variable.
* Map them to your design system's variables, so a change there reaches the forms too.
* CraftForms keeps control of how states look (focus ring, invalid and valid fields, error messages, custom controls, step progress). The variables give them their colours and sizes.

#### What wins

From weakest to strongest:

1. The form style's own value.
2. Settings → Form styles: what the theme gives (Automatic), then the values typed there. CraftForms prints these as `:where(:root) { … }`, with zero specificity.
3. Your `--cf-form-*` variables in your own CSS: any `:root` rule, wrapper or form class beats step 2.
4. Settings for one form: the CraftForms element in Bricks, Elementor or Divi, and the Form block's own colours and spacing.
5. Your own CSS rules on the elements themselves.

The rules CraftForms adds for these variables use `:where()` too, so any rule in your theme or builder wins over them.

### The variables

| Variable                       | What it changes                                                                                                                 | Default          | Modern           | Builderius CSS           | Unstyled               |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- | ---------------- | ---------------- | ------------------------ | ---------------------- |
| `--cf-form-accent`             | Selected option cards and swatches, payment choice, step progress, upload drop zone, button fill (when no button colour is set) | `#1a1a1a`        | `#3b4ce2`        | framework primary        | `currentColor`         |
| `--cf-form-on-accent`          | Text on an accent fill (checked swatches, selected time slots, button text)                                                     | `#fff`           | `#fff`           | `#fff`                   | —                      |
| `--cf-form-focus`              | Focus colour of fields                                                                                                          | accent           | accent           | framework base 600       | `currentColor`         |
| `--cf-form-text`               | Text in fields                                                                                                                  | browser default  | `#20242f`        | framework text colour    | your theme             |
| `--cf-form-text-muted`         | Placeholders (Modern), option descriptions                                                                                      | —                | `#929292`        | —                        | —                      |
| `--cf-form-label-color`        | Label colour                                                                                                                    | inherited        | inherited        | inherited                | inherited              |
| `--cf-form-field-bg`           | Field background                                                                                                                | browser default  | `#f9fafb`        | browser default          | your theme             |
| `--cf-form-border`             | Field borders                                                                                                                   | `#c0c4c9`        | `#c0c4c9`        | framework base 200       | 35% of the text colour |
| `--cf-form-error`              | Invalid fields and error text                                                                                                   | `#c44d4d`        | `#c44d4d`        | framework error colour   | —                      |
| `--cf-form-success`            | Valid fields                                                                                                                    | `#51a88a`        | `#51a88a`        | framework success colour | —                      |
| `--cf-form-font-family`        | The form's font                                                                                                                 | inherited        | inherited        | framework font           | inherited              |
| `--cf-form-font-size`          | Field text size                                                                                                                 | `1rem`           | —                | inherited                | inherited              |
| `--cf-form-label-size`         | Label size                                                                                                                      | inherited        | inherited        | inherited                | inherited              |
| `--cf-form-label-weight`       | Label weight                                                                                                                    | inherited        | inherited        | inherited                | inherited              |
| `--cf-form-option-size`        | Option and swatch text                                                                                                          | `0.8em`          | `0.8em`          | `0.875em`                | inherited              |
| `--cf-form-error-size`         | Error message text                                                                                                              | `0.8em`          | —                | —                        | `0.875em`              |
| `--cf-form-gap`                | Space between fields                                                                                                            | `2rem`           | `2rem`           | framework block spacing  | `2rem`                 |
| `--cf-form-field-gap`          | Space between a label, its field and its help                                                                                   | theme spacing 20 | theme spacing 20 | framework xs             | theme spacing 20       |
| `--cf-form-options-gap`        | Space between options                                                                                                           | theme spacing 20 | theme spacing 20 | framework xs             | theme spacing 20       |
| `--cf-form-input-padding`      | Padding inside fields                                                                                                           | theme spacing 20 | theme spacing 20 | framework sm             | `0.5em`                |
| `--cf-form-radius`             | Field corners                                                                                                                   | `4px`            | `0.25rem`        | framework xs             | —                      |
| `--cf-form-card-radius`        | Option cards and payment choice corners                                                                                         | field radius     | `12px` (payment) | framework sm             | —                      |
| `--cf-form-border-width`       | Field and card border width                                                                                                     | `1px`            | —                | framework border width   | —                      |
| `--cf-form-button-bg`          | Submit button fill (and outline colour)                                                                                         | `#007cba`        | `#007cba`        | framework button         | your theme's button    |
| `--cf-form-button-bg-hover`    | Submit button fill on hover                                                                                                     | `#005a87`        | `#005a87`        | framework button         | your theme's button    |
| `--cf-form-button-text`        | Submit button text                                                                                                              | `#fff`           | `#fff`           | framework button         | your theme's button    |
| `--cf-form-button-radius`      | Submit button corners                                                                                                           | `4px`            | `4px`            | framework button         | your theme's button    |
| `--cf-form-button-padding`     | Submit button padding                                                                                                           | `12px 24px`      | `12px 24px`      | framework button         | your theme's button    |
| `--cf-form-button-font-weight` | Submit button weight                                                                                                            | `600`            | `600`            | framework button         | your theme's button    |

"Theme spacing 20" is `--wp--preset--spacing--20`, falling back to `0.5rem`. A dash means the style doesn't draw that part, so the variable has no effect there.

#### Notes per style

* **Builderius CSS** and **Unstyled** leave text fields, selects and text areas to your framework or theme: border, radius, padding and font size come from there. The variables still reach everything CraftForms draws itself (option cards, swatches, time slots, the payment choice, errors, spacing).
* **Unstyled** keeps your theme's button (`wp-element-button`) and fields: the button and field variables don't apply.
* **Modern** uses its accent for focus too.

#### The submit button and labels

The submit button on its default style and the labels look like your theme's until you set their variables: a theme that colours every `label` or styles every button keeps doing so. Set `--cf-form-label-color` or any `--cf-form-button-*` variable (in Settings → Form styles, your own CSS, or the page a form is embedded on) and CraftForms writes it onto the button or the labels, over the theme's rule. Only the variables you set are written; a variable that names something your page doesn't define counts as not set.

### Stable classes

These class names are kept across versions; a rename keeps the old name working for at least one major version.

| Element                               | Class                                                                                                                                                                                                                                                                |
| ------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| The form                              | `.wp-block-craftforms-form` (plus `.is-style-modern`, `.is-style-builderius`, `.is-style-inherit` for the chosen style; Default has none or `.is-style-default`)                                                                                                     |
| A field and its label, input and help | `.wp-block-craftforms-text-input-field`, `-textarea-field`, `-select-field`, `-radio-field`, `-checkboxes-field`, `-booking-datepicker-field`, `-file-field`, `-range-slider-field`, `-color-picker-field`, `-repeater-field` (each prefixed `.wp-block-craftforms`) |
| Label                                 | `.wp-block-craftforms-label`                                                                                                                                                                                                                                         |
| Text field, text area, select         | `.wp-block-craftforms-text-input`, `.wp-block-craftforms-textarea`, `.wp-block-craftforms-select`                                                                                                                                                                    |
| Options                               | `.craftforms-options-group`; each option `.wp-block-craftforms-radio-option` / `.wp-block-craftforms-checkbox-option`; card layout `.cf-field-card`                                                                                                                  |
| Error message                         | `.wp-block-craftforms-form-error`                                                                                                                                                                                                                                    |
| Submit button                         | `.wp-block-craftforms-submit-button` (`.is-style-fill` / `.is-style-outline` when a style is picked)                                                                                                                                                                 |
| Date field                            | `.craftforms-datepicker-input`                                                                                                                                                                                                                                       |
| Colour field                          | `.cf-cp-input`                                                                                                                                                                                                                                                       |

### Static sites and other websites

A form shown on a website that isn't your WordPress site (a static HTML site, Webflow, Framer, a React or Vue app) comes through **CraftForms → Embed** (PRO; see [Embed](https://kb.craftformswp.com/documentation/form-building/embed.md)). The embedded form is ordinary markup on that page, not an iframe: it loads CraftForms' stylesheets next to it, and the page's own CSS reaches it like any other element.

* **Your Settings → Form styles values travel with the embed.** A plain value (`#0f766e`, `6px`) looks the same on the other website. A value that names a variable (`var(--bricks-color-primary)`) is looked up on the **other** website: if that site has the same variable (it uses the same framework), it's used; if not, the form falls back to its style's own value.
* **Set the variables in the other website's CSS** to match it. A `:root` rule there wins over the values from your WordPress site:

```css
/* The stylesheet of the website the form is embedded on */
:root {
  --cf-form-accent: #e4572e;
  --cf-form-border: #d6d3d1;
  --cf-form-radius: 10px;
  --cf-form-font-family: "Inter", system-ui, sans-serif;
}
```

* **No stylesheet to edit** (a site builder's embed box)? Put the variables on the snippet's own `div`. They reach the form inside it:

```html
<div data-craftforms-embed="YOUR_KEY"
     style="--cf-form-accent:#e4572e;--cf-form-radius:10px;--cf-form-border:#d6d3d1">
</div>
```

* **Tailwind or another utility framework:** map the variables to your theme values once, in your base CSS. Tailwind 4 exposes its theme as CSS variables:

```css
@layer base {
  :root {
    --cf-form-accent: var(--color-indigo-600);
    --cf-form-border: var(--color-slate-300);
    --cf-form-radius: var(--radius-md);
    --cf-form-font-family: var(--font-sans);
  }
}
```

On Tailwind 3, write `theme(colors.indigo.600)` and so on instead of `var(…)`.

* **The loading spinner** has its own variables (`--craftforms-embed-loader-color` and others): see [Embed → Styling](https://kb.craftformswp.com/documentation/form-building/embed.md#styling).
* **A WordPress site exported to static HTML** (Simply Static and similar) keeps the forms' stylesheets and the Form styles values in the exported pages: nothing to change.

### Examples

**theme.json colours and spacing (any block theme):**

```css
:root {
  --cf-form-accent: var(--wp--preset--color--primary);
  --cf-form-text: var(--wp--preset--color--contrast);
  --cf-form-field-bg: var(--wp--preset--color--base);
  --cf-form-gap: var(--wp--preset--spacing--40);
}
```

Use the slugs your theme defines (Site Editor → Styles → Colours shows them). Block themes are followed automatically on new sites (see [Form Styles](https://kb.craftformswp.com/documentation/form-building/form-styles.md)); this is for older sites or other choices.

**Automatic.css 4:**

```css
:root {
  --cf-form-accent: var(--primary);
  --cf-form-border: var(--border-color-dark);
  --cf-form-radius: var(--radius);
  --cf-form-gap: var(--space-m);
  --cf-form-button-bg: var(--primary);
  --cf-form-button-bg-hover: var(--primary-hover);
  --cf-form-button-text: var(--primary-ultra-light);
}
```

**One form only:** give the Form block an extra class (Advanced → Additional CSS class, for example `signup`) and set the variables on it:

```css
.signup { --cf-form-accent: #0f766e; --cf-form-radius: 999px; }
```

**Dark section:**

```css
.dark-band {
  --cf-form-text: #f1f5f9;
  --cf-form-field-bg: #0f172a;
  --cf-form-border: #334155;
  --cf-form-accent: #38bdf8;
  --cf-form-on-accent: #0f172a;
  --cf-form-label-color: #e2e8f0;
}
```

### For developers: map any framework in code

The mapping is provider-agnostic: any theme, framework or builder can map its own variables to the form variables in PHP, without the settings page. Keys are the variable names without `--cf-form-`.

**Site-wide** (on top of Settings → Form styles, Automatic included):

```php
add_filter('craftforms_form_style_tokens', function (array $tokens) {
    return [
        'accent'    => 'var(--fancy-primary)',
        'radius'    => 'var(--fancy-radius-s)',
        'button-bg' => 'var(--fancy-primary)',
    ] + $tokens; // the settings page wins where both set a value; swap the operands to win yourself
});
```

**One form** (by its ID; written onto that form only):

```php
add_filter('craftforms_form_style_tokens_for_form', function (array $tokens, int $form_id) {
    return 123 === $form_id ? ['accent' => 'var(--brand-orange)'] : $tokens;
}, 10, 2);
```

#### Classes in code

The classes from **Settings → Form styles → Classes** come from `craftforms_form_style_classes` (all forms) and `craftforms_form_style_classes_for_form` (one form). Each is a list of element => space-separated classes; elements: `form`, `field`, `label`, `input`, `help`, `error`, `button`, `button-secondary`, `option`, `steps`.

```php
add_filter( 'craftforms_form_style_classes', function ( $classes ) {
    $classes['button'] = 'btn--primary';
    $classes['input']  = 'form-input';
    return $classes;
} );

add_filter( 'craftforms_form_style_classes_for_form', function ( $classes, $form_id ) {
    if ( 42 === $form_id ) {
        $classes['button'] = 'btn--primary btn--l';
    }
    return $classes;
}, 10, 2 );
```

Only valid class names are kept (at most 12 per element). They are added to the rendered markup, so they reach embeds too.

#### Your own preset

A theme, framework or plugin can ship its own preset. It shows in Settings → Form styles → **Start from**, and when `detected` is true it is what **Automatic** follows, ahead of the built-in presets:

```php
add_filter('craftforms_form_style_presets', function (array $presets) {
    $presets[] = [
        'id'       => 'fancy',
        'label'    => 'Fancy framework',
        'detected' => defined('FANCY_FRAMEWORK_VERSION'), // true = this site runs it
        'tokens'   => ['accent' => 'var(--fancy-primary)', 'text' => 'var(--fancy-text)'],
    ];
    return $presets;
});
```

Built-in preset ids, in the order Automatic picks them when more than one is active: `core-framework`, `automatic-css`, `automatic-css-3`; `bricks`, `blocksy`, `kadence`, `divi`, `builderius`; `elementor`; `theme-json`. Return a preset with the same id to replace a built-in one.

Values from code are checked like values typed on the page: a CSS value or `var(--name)`, nothing that could break out of the declaration (no `{ } ; < >`, `url()`, `@` rules or comments). Settings → Form styles lists what code sets, read-only.
