Shadow DOM Support

SurveyJS Form Library can be rendered inside the Shadow DOM to isolate its markup and styles from the rest of the page. This approach is useful in applications that require strict style encapsulation, such as component-based architectures or when integrating SurveyJS into third-party environments.

When rendered in the Shadow DOM, the survey behaves the same as in the regular DOM, but its styles do not leak out, and external styles do not affect it unless explicitly shared.

Benefits

Rendering a survey in the Shadow DOM provides the following advantages:

  • Style encapsulation
    Prevents global styles from affecting survey elements and avoids unintended overrides.

  • No CSS conflicts
    Eliminates naming collisions between SurveyJS styles and application styles.

  • Safer embedding
    Makes it easier to integrate surveys into complex applications, widgets, or micro-frontends.

  • Predictable rendering
    Ensures consistent appearance regardless of the host application's styling.

Render Survey in Shadow DOM

Angular

Import the SurveyJS Form Library stylesheet and set the component's encapsulation property to ViewEncapsulation.ShadowDom:

import { Component, OnInit, ViewEncapsulation } from "@angular/core";
// ...
import "survey-core/survey-core.css";

@Component({
  selector: "component-survey",
  templateUrl: "./survey.component.html",
  styleUrls: ["./survey.component.css"],
  encapsulation: ViewEncapsulation.ShadowDom
})
export class SurveyComponent implements OnInit {
  // ...
}

View Demo

React

Append the survey-core.css stylesheet to the shadow root instead of importing it into the component:

import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";

const shadowHost = document.getElementById('root');
const shadowRoot = shadowHost.attachShadow({ mode: 'open' });

const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://unpkg.com/survey-core/survey-core.min.css";

shadowRoot.appendChild(link);

const root = createRoot(shadowRoot);
root.render(<App />);

View Demo

Vue

Append the survey-core.css stylesheet to the shadow root instead of importing it into the component. Add the stylesheet after mounting:

import { createApp } from "vue";
import App from "./App.vue";

const app = createApp(App);
const shadowHost = document.getElementById("app");
const shadowRoot = shadowHost.attachShadow({ mode: "open" });

app.mount(shadowRoot);

const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://unpkg.com/survey-core/survey-core.min.css";

shadowRoot.appendChild(link);

View Demo

HTML/JS/CSS

Append the survey-core.css stylesheet to the shadow root instead of referencing it globally:

const shadowHost = document.getElementById("root");
const shadowRoot = shadowHost.attachShadow({ mode: "open" });

const link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://unpkg.com/survey-core/survey-core.min.css";

shadowRoot.appendChild(link);

const surveyElement = document.createElement("div");
shadowRoot.appendChild(surveyElement);

const survey = new Survey.Model(json);
survey.render(surveyElement);

View Demo

Send feedback to the SurveyJS team

Need help? Visit our support page

Your cookie settings

We use cookies to make your browsing experience more convenient and personal. Some cookies are essential, while others help us analyse traffic. Your personal data and cookies may be used for ad personalization. By clicking “Accept All”, you consent to the use of all cookies as described in our Terms of Use and Privacy Statement. You can manage your preferences in “Cookie settings.”

Your renewal subscription expires soon.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.

Your renewal subscription has expired.

Since the license is perpetual, you will still have permanent access to the product versions released within the first 12 month of the original purchase date.

If you wish to continue receiving technical support from our Help Desk specialists and maintain access to the latest product updates, make sure to renew your subscription by clicking the "Renew" button below.