Skip to content
All articles

Product guides

Shadow DOM: why the widget cannot break your CSS

How Provedly uses Shadow DOM to keep its styles and your site's styles apart, what that protects against, and the few things isolation does not cover.

Provedly team··5 min read

Every third-party widget carries the same risk: its CSS leaks into your page, or your CSS leaks into it, and someone spends an afternoon with devtools. Provedly renders inside a Shadow DOM, which means the browser itself draws a boundary that normal CSS selectors cannot cross in either direction. This post explains what that boundary does, what it protects you from, and the handful of things it deliberately does not isolate.

What Shadow DOM is

Shadow DOM is a browser standard that lets a script attach a separate, encapsulated DOM tree to an element. Styles defined inside the shadow tree apply only inside it; styles defined in the page do not reach in. It is the mechanism behind native elements like <video> controls, and it is available in every current browser.

When the Provedly loader runs, it creates a host element, attaches a shadow root, and renders the toast, counter or bar inside that root with its own stylesheet. From your page's point of view there is one empty-looking element at the end of <body>.

<!-- what your page sees -->
<provedly-widget></provedly-widget>
#shadow-root
<style>
    …widget styles…
</style>
<div class="toast">…</div>

What it protects you from

Your resets do not flatten the widget. A global * { box-sizing: border-box; margin: 0 } or a Tailwind preflight does not apply inside the shadow root. The toast looks the same on a site with aggressive resets as on one with none.

The widget's classes do not collide with yours. The widget can use a class named .toast or .badge and it will never match an element in your page, and your .badge rule will never match the widget's.

Your !important rules stay yours. A theme that declares p { font-size: 18px !important } would normally override any widget paragraph. Inside a shadow root it is simply not in scope.

Framework CSS stays put. CSS Modules, styled-components, Vue scoped styles, Svelte scoped styles: none of them interact with the widget, and the widget does not interact with them. This is why the install on Next.js, Webflow, WordPress and Shopify is the same one script tag; there is no per-platform stylesheet work. See Adding social proof to a Next.js app.

Fonts stay predictable. The widget's own stylesheet controls its typography, so a display typeface declared on your body does not turn a notification into a headline.

What it does not isolate, on purpose

Shadow DOM scopes styles. It does not scope the viewport, the stacking context, or user interaction, and there are a few places where your page and the widget still share space.

Shared Why it matters What to do
Viewport position The toast is position: fixed and competes with your other fixed elements Choose a corner that is free; use device targeting if mobile is crowded
Stacking order The host element has a z-index; a page element with a higher one can cover it Rare; usually a full-screen overlay, which should cover it anyway
body { overflow: hidden } Does not affect the widget, but your own modals may expect the corner to be empty Nothing, unless you want the toast hidden during modals; use URL targeting for distinct routes
Inherited CSS custom properties Custom properties do cross the shadow boundary by design The widget does not rely on page variables, so this has no visible effect
Pointer events Clicking the badge opens the verification page, like any link None

The one practical collision is other fixed-position elements: chat launchers, cookie banners, sticky add-to-cart buttons. Shadow DOM cannot make two things occupy the same corner. Pick positions so they do not.

Styling the widget

Because you cannot reach inside the shadow root from your stylesheet, the design controls live in the dashboard: five themes (Clean white, Deep ocean, Midnight, Electric violet, Sunset blaze), position, avatar style, name and location formats, and for bars, layout, digit style, font size, maximum width and button colours. This is a constraint and a feature. It guarantees that the preview in the dashboard is what visitors see, on every site, regardless of the site's CSS. See Choosing a toast theme that matches your brand.

If you need something the controls do not offer, the answer is not to pierce the shadow root with ::part or by walking shadowRoot in JavaScript. Those approaches break on the next widget release.

Performance implications

The shadow root is created once per page load. Styles inside it are parsed once and do not trigger recalculation of your page's styles, because the browser treats the two trees separately for cascade purposes. The widget's bundle is about 6 KB gzipped, loads async defer, and renders fixed-position elements that do not participate in your layout, so there is no layout shift to measure. More in Page speed and social proof scripts.

Debugging

In devtools, the widget appears as the host element with a #shadow-root (open) child. Expand it to inspect the toast like any other element. Current versions of Chrome and Firefox show shadow trees by default; if your browser hides them, look for a "show user agent shadow DOM" or similar option in the devtools settings. If the toast is not visible at all, the usual causes are outside the shadow root: the domain is not on the site's allowed list, the widget has no records, or the page is excluded by URL targeting.

Frequently asked questions

Does Shadow DOM work in every browser my visitors use?

Shadow DOM has been supported in all evergreen browsers for years. Provedly does not target browsers without it.

Can my Content Security Policy block the inline styles inside the shadow root?

A strict style-src without 'unsafe-inline' can affect how styles are applied inside a shadow root depending on the browser. If you run such a policy, test the widget on staging and consult the docs for the recommended CSP entries for provedly.app.

Does the live counter use the same shadow root?

The toast and counter from one widget token render inside the same host. A CTA bar loaded from cta.js has its own host and its own shadow root.

See the isolation on your own site in one script tag: install free.

shadow domcssengineering

Get new articles by email

Honest social proof, verified purchases and what actually moves conversion. A few emails a month at most; leave with one click.

We email you once to confirm. Your address is used only for this newsletter; see the privacy policy.

Show proof you can stand behind.

Free plan, one site, 2,000 impressions a month, verified purchases included. The badge on the free plan links to your verification page, which is the point.