Adding a chat widget means putting someone else's code on your website. That raises two worries for the site owner. Will the widget break my page, changing fonts or layouts through stray styles? And will my page break the widget, so that a global style rule turns its buttons into something unrecognisable? Both happen more often than they should, especially on sites built with page builders or heavy themes. Modern browsers offer a mechanism designed for exactly this problem: Shadow DOM. It lets a widget draw itself inside a sealed compartment of the page where its styles and structure are separate from everything else. This guide explains in plain language what Shadow DOM is, how it compares with the older approach of using an iframe, what it does and does not protect, where accessibility and other trade-offs arise, and how to test that any widget will behave on your site. Crescelo's widget uses a Shadow DOM; a separate embedded page option uses an iframe.
The problem: styles collide
Web pages use CSS rules to control appearance, and rules can apply broadly. A site theme might say that every button is orange with large text, or that all paragraphs have a certain margin. A widget's buttons and text are ordinary page elements, so those rules can reach them and distort the widget. In the other direction, a widget with carelessly written CSS can change the appearance of the site's own elements.
| Collision | Symptom |
|---|---|
| Site styles hit the widget | Distorted buttons, wrong fonts, overlapping text in the chat |
| Widget styles hit the site | Your headings or links change after the widget loads |
| Class name clash | Both use a class named 'button' or 'container' with different meanings |
| Script conflicts | Two scripts overwrite each other's global variables |
What Shadow DOM is
Shadow DOM lets a script attach a hidden, self-contained tree of elements to a host element on the page. Styles defined inside it apply only inside it, and most styles from the page do not leak in. The widget appears on the page like any element, but it has its own sealed styling scope. It is a standard part of modern browsers, not a special plug-in.
- Style isolation: the widget's CSS stays inside; the page's CSS does not restyle it.
- No class-name clashes: names inside do not conflict with names outside.
- Clean markup: the widget sits under a single host element, keeping your page structure tidy.
- Some things do pass through, such as inherited properties like font family and colour unless the widget resets them, which a well-built widget does explicitly.
Shadow DOM versus iframe
| Aspect | Shadow DOM | Iframe |
|---|---|---|
| Style isolation | Strong for CSS | Complete; separate document |
| Script isolation | Shares the page's JavaScript environment | Separate; cannot touch the page's scripts |
| Security boundary | Not a security boundary | A stronger boundary, particularly across origins |
| Performance | Light; part of the page | Heavier; a separate page load |
| Integration | Can respond to page events, size and layout naturally | Needs messages to communicate with the page |
| Accessibility and focus | Behaves like page content when done properly | Needs care for focus and screen readers across the frame |
| Best for | A floating widget that should feel part of the site | Embedding a whole page or app that must be fully isolated |
Neither is universally better. A floating chat bubble suits Shadow DOM. Embedding a full application, such as a booking page or a hosted chat page inside another site, suits an iframe. Crescelo uses a Shadow DOM for its website widget and offers an embeddable page for other placements.
What Shadow DOM does not do
- It is not a security sandbox: scripts on your page can still reach into an open shadow tree, so it does not stop a malicious script on your own site.
- It does not protect against slow scripts or heavy loads; performance is a separate concern.
- It does not replace good CSS hygiene inside the widget.
- It does not fix accessibility problems by itself.
Security for the conversation comes from the server side: rate limits, signed tokens and workspace checks; see signed visitor tokens.
Accessibility notes
- Keyboard users must be able to reach the launcher, open the chat, move through it and close it.
- Focus should move sensibly when the chat opens and return when it closes.
- The chat should have suitable labels for screen readers.
- Text must have sufficient contrast, including with your custom colours.
- Streaming text should not flood screen readers with repeated announcements.
- Respect reduced-motion preferences.
Shadow DOM changes how some assistive technology and testing tools find elements, but modern screen readers handle it well. Test with a screen reader and keyboard on your own site. See accessibility and WCAG for chatbots.
Other practical points
- Page builders and themes: they are the most common source of style conflicts, so isolation helps most there.
- Content security policy: if your site restricts scripts and styles, the widget's host must be allowed.
- Cookie banners and other floating elements: check stacking and overlap on mobile.
- Loading: the widget should load after your main content so it does not delay your page; see performance of embedded chat widgets.
- Duplicates: a well-built widget checks that it is not already loaded, so pasting the code twice does not create two chat bubbles.
How to test a widget on your site
| Test | What to look for |
|---|---|
| Load your busiest page on a phone | Widget appears, does not cover key buttons |
| Compare the page before and after installing | No changes in fonts, spacing or colours |
| Use only the keyboard | Launcher reachable, chat operable, focus returns |
| Turn on a screen reader | Announcements sensible, labels present |
| Test with your theme's dark mode or high-contrast mode | Text remains readable |
| Check page speed before and after | No large drop |
Do this on a staging copy first if you have one.
Common mistakes
- Assuming any widget is safe for your styles.
- Treating Shadow DOM as a security feature.
- Forgetting mobile tests.
- Installing the code twice.
- Ignoring keyboard and screen reader use.
- Overriding colours without checking contrast.
A ten-minute pre-launch checklist
- Install the widget on a staging or hidden page first.
- Open the page on a phone and a desktop and take screenshots before and after.
- Tab through the page with the keyboard and open the chat.
- Change the widget colours and check text contrast.
- Reload with a slow connection and confirm the page content appears first.
- Then install on the live site and check again.
This short routine catches nearly all the problems that owners meet with third-party widgets, and it makes a useful habit for any script you add to your site.
Frequently asked questions
What is Shadow DOM?
A browser feature that lets a widget draw itself inside a sealed section of the page, so its styles and structure do not clash with your site's.
Does Crescelo's widget use Shadow DOM?
Yes. The website widget renders inside a Shadow DOM, and a separate embeddable page option uses an iframe.
Is Shadow DOM more secure than an iframe?
No. It isolates styles, not security. An iframe from another origin is a stronger boundary.
Will the widget change my site's appearance?
A well-isolated widget should not. Compare the page before and after to confirm.
Is it accessible?
It can be, if built with keyboard support, focus management, labels and contrast. Test it on your site.
Can I use both approaches?
Yes. Use the floating widget for general pages and an embedded page where you want a full-page experience.
See the website widget feature, pricing and read how a chat widget is built.
Further reading
- Google Search Central: creating helpful, people-first content: What Google looks for in useful pages.
RESPONDE A CADA VISITANTE. RESERVA CITA A QUIEN ESTÁ LISTO.
Instala Crescelo en tu sitio web en 15 minutos
Entrena a tu asistente con tus listas de precios, documentos y condiciones de servicio. Activa respuestas basadas en tus fuentes las 24 horas y reservas de citas en el chat sin solapamientos.