How to Style HubSpot Forms in the New Form Editor (v4)

HubSpot v4 forms

Forms built in HubSpot's new form editor are embedded in an iframe by default, so your page CSS can't reach them. To style them with your own CSS, use HubSpot's raw HTML (developer) embed, which renders the form directly in the page, then style it with the --hsf-* CSS variables and .hsfc-* classes.

We ran into this while building the lead form for our Smart Calculator HubSpot module, which has to match whatever theme it's placed in. This tutorial shows the approach that worked, with the code.

Why your CSS stopped working

Forms from the legacy form editor render straight into the page, so CSS like .hs-form input { ... } styles them. Forms from the new editor are different: the standard embed, and HubSpot's

tag in themes, output a placeholder element with the class hs-form-frame, and HubSpot's script loads the form inside an iframe. An iframe is a separate document, so selectors on your page don't apply inside it.

You have three options, from simplest to most flexible.

Option 1: Use the form editor's style settings

The new form editor has its own style options for fonts, colors, buttons and field shapes. If you only need the form to roughly match your brand, set them there. It needs no code, but you can't match a theme exactly, and every form has to be styled one by one.

Option 2: Use the raw HTML embed and style it with CSS

HubSpot also offers a developer embed that renders the form as normal HTML in your page. It looks like this:

<div class="hs-form-html"
     data-region="na1"
     data-form-id="YOUR-FORM-ID"
     data-portal-id="YOUR-PORTAL-ID"></div>

<script src="https://js.hsforms.net/forms/embed/developer/YOUR-PORTAL-ID.js" defer></script>

Notes:

  • Use the region your portal lives in. For portals outside na1 the script host includes the region, for example js-eu1.hsforms.net.
  • Load the script once per page, even if the page has several forms.
  • You can find the form ID in the form editor's URL or embed code.

Style it with CSS variables

The rendered form reads its styles from CSS custom properties that start with --hsf-. Set them on the form's renderer element and the whole form follows:

.my-form [data-hsfc-id="Renderer"],
.my-form .hsfc-Renderer {
  --hsf-global__font-family: inherit;
  --hsf-global__color: #1f2933;
  --hsf-background__background-color: transparent;
  --hsf-background__padding: 0;
  --hsf-field-label__color: #111417;
  --hsf-field-label__font-size: 0.875rem;
  --hsf-field-input__background-color: #ffffff;
  --hsf-field-input__border-color: #d5dbe1;
  --hsf-field-input__border-radius: 10px;
  --hsf-field-input__placeholder-color: #8f9aa4;
  --hsf-button__background-color: #fe5900;
  --hsf-button__color: #ffffff;
  --hsf-button__border-radius: 12px;
  --hsf-button__width: 100%;
  --hsf-erroralert__color: #ef4444;
  --hsf-row__vertical-spacing: 1rem;
}

Pointing these variables at your theme's own variables, for example var(--brand-primary), makes every form follow your theme automatically.

Fine-tune with .hsfc-* classes

For anything the variables don't cover, the rendered elements have stable class names starting with hsfc-, such as .hsfc-FieldLabel, .hsfc-TextInput, .hsfc-Button, .hsfc-RichText and .hsfc-Step__Content. Scope your rules to a wrapper so they don't leak:

.my-form .hsfc-RichText p { margin: 0 0 0.5rem; }
.my-form .hsfc-Button { font-weight: 600; letter-spacing: 0.01em; }

Option 3: Inside a HubSpot module, swap the iframe embed automatically

In a theme or module, editors pick a form with a form field and the

tag renders the iframe version. In our Smart Calculator module we render that output inside a <template>, read the form and portal IDs from it, and replace it with the raw HTML embed in the browser. Legacy forms, which don't produce an hs-form-frame, are left as they are:

<div class="my-form">
  <template data-form-src>

</template> <script> (function (tpl) { var frame = tpl.content.querySelector(".hs-form-frame"); if (!frame) { tpl.replaceWith(document.importNode(tpl.content, true)); return; } var box = document.createElement("div"); box.className = "hs-form-html"; ["data-region", "data-form-id", "data-portal-id", "data-env"].forEach(function (a) { if (frame.getAttribute(a)) box.setAttribute(a, frame.getAttribute(a)); }); tpl.replaceWith(box); if (!document.querySelector("script[data-hsf-dev]")) { var region = frame.getAttribute("data-region"); var s = document.createElement("script"); s.src = "https://js" + (region && region !== "na1" ? "-" + region : "") + ".hsforms.net/forms/embed/developer/" + frame.getAttribute("data-portal-id") + ".js"; s.defer = true; s.setAttribute("data-hsf-dev", ""); document.head.appendChild(s); } })(document.currentScript.previousElementSibling); </script> </div>

This simplified version skips one detail: if you also insert a legacy form this way, its own scripts need to be re-run, because scripts inside a <template> don't execute when moved.

Gotchas we hit

  • Legacy forms behave differently. Forms from the old editor still render with the classic .hs-form markup and don't use --hsf-* variables, so keep your old CSS for them.
  • Field names changed. In the new forms, inputs are named with an object prefix, for example 0-1/email for a contact property. Update any JavaScript that finds fields by name.
  • The form appears after the script loads. Reserve some height on the wrapper to avoid layout shift while it renders.
  • Don't load the developer script twice. Check for an existing script tag before adding one, as in the example above.
  • Test the submit flow, including the thank-you message or redirect, after switching embeds.

Frequently asked questions

Can I style a HubSpot form inside an iframe with CSS?

Not from your page's stylesheet. Use the form editor's style settings, or switch to the raw HTML embed so the form is part of your page.

Does the raw HTML embed still create contacts in HubSpot?

Yes. It is HubSpot's own embed, so submissions, contact creation and form analytics work as with the standard embed.

Do these CSS variables work on legacy forms?

No. The --hsf-* variables and .hsfc-* classes belong to forms from the new editor.

Need forms that match your theme everywhere?

We build custom HubSpot modules and themes where forms, calculators and lead capture follow your brand automatically. If your forms don't look right, hire a HubSpot developer from our team to fix them.

Keep reading

All posts

Work with us

Need help with your HubSpot site?

Book a free consultation with a HubSpot developer. We look at your site and give you a fixed-price plan.

Fixed prices · Replies within one business day