Developers

Theming with CSS

Override an embedded form's colours, fonts and spacing with CSS variables, choose light or dark mode, and decide whether the form renders in a shadow root.

Most teams should style forms in Appearance, which needs no code and also styles the hosted form link. Use this page when the page you embed the form in needs to control its look in code.

An embedded form restyled with a serif font, square corners and a dark red primary colour An embedded form restyled with a serif font, square corners and a dark red primary colour

What wins

The embedded form works out each value in this order:

  1. The theme attribute on <formwork-form> sets the mode, overriding the mode saved in Appearance.
  2. --formwork-* variables set on the <formwork-form> element override the saved values.
  3. Values saved in Appearance for the form version apply next.
  4. Built-in defaults fill in anything else.

Appearance is part of the form version, so a draft and the published form can look different until you publish. See Drafts and publishing.

Choose light or dark

<formwork-form form-id="FORM_ID" theme="dark"></formwork-form>
ValueResult
autoFollows the visitor’s light or dark setting
lightAlways light
darkAlways dark

Any other value is treated as auto. You can change the attribute at any time and the form updates.

Colour variables

Each colour has a light and a dark version. Replace {mode} with light or dark, for example --formwork-dark-primary.

VariableUsed forLight defaultDark default
--formwork-{mode}-primaryButtons, focus rings and highlights#374151#dbe2e7
--formwork-{mode}-bgBackground around the formtransparent#111820
--formwork-{mode}-card-bgForm and control surfaces#ffffff#1f2933
--formwork-{mode}-text-primaryMain text#1f2933#f4f7f8
--formwork-{mode}-text-secondarySupporting text#5f6c76#c3ccd2
--formwork-{mode}-text-tertiaryMuted text#65737d#94a0a9
--formwork-{mode}-borderBorders#d7dde2#3d4a54
--formwork-{mode}-border-lightSubtle dividers#eef2f4#2c3740
--formwork-{mode}-errorError text and borders#b42318#ff8a7a
--formwork-{mode}-error-bgError backgrounds#fff4f2#2b1a17
--formwork-{mode}-shadowCard shadowA soft shadowA soft shadow
--formwork-{mode}-shadow-smSmall control shadowNoneNone

Hover and tinted versions of the primary and error colours are worked out from these, so you don’t set them separately.

Layout and type variables

These apply in both modes.

VariableUsed forDefault
--formwork-spacingBase spacing unit. Other gaps are multiples of it.8px
--formwork-radiusCorner radius. Smaller and larger corners are worked out from it.7px
--formwork-radius-fullRound buttons, such as those on repeating items50%
--formwork-font-familyBody textThe system font
--formwork-font-family-headingsHeadingsSame as the body font
--formwork-max-widthMaximum width of the form680px
--formwork-scroll-offsetSpace to leave at the top when the form scrolls into view, for sticky headers0px

Fonts set with these variables must be loaded by your page. FormWork only loads the Google Fonts you choose in Appearance.

Example

<style>
  #support-form {
    --formwork-light-primary: #0f766e;
    --formwork-dark-primary: #2dd4bf;
    --formwork-light-bg: #f8fafc;
    --formwork-light-text-primary: #0f172a;
    --formwork-light-border: #cbd5e1;
    --formwork-radius: 4px;
    --formwork-font-family: Inter, sans-serif;
    --formwork-max-width: 720px;
  }
</style>

<formwork-form id="support-form" form-id="FORM_ID"></formwork-form>
<script src="https://app.useformwork.com/static/client.js" type="module"></script>

Set the variables on the <formwork-form> element itself or on an ancestor. Setting a light value has no effect while the form is in dark mode, so set both versions of a colour if visitors can see either mode.

Shadow DOM and light DOM

By default the form renders inside a shadow root. CSS variables cross into it, but your page’s other selectors don’t, so site styles can’t break the form and you can’t restyle individual controls.

Set render-mode="light" only when the form must be part of the page’s normal DOM. The form still brings its own stylesheet, but broad selectors on your page can now affect it, so test carefully.

<formwork-form form-id="FORM_ID" render-mode="light"></formwork-form>

Class names and the internal structure of the form are not a supported interface and may change. Style through the variables above.

Troubleshooting

ProblemCheck
Colours from Appearance don’t showLook for --formwork-* variables on the element or an ancestor that override them.
auto always looks lightCheck the device’s dark mode setting.
Your selectors have no effectThe shadow root isolates the form. Use variables, or light DOM on purpose.
A custom font falls backYour page must load the font, unless it is one of the Appearance fonts.
The draft and live form look differentAppearance is saved per version. Publish the draft to apply its appearance.

Something missing or unclear? Tell us.