# Email preview in a div leaks styles: render it in a sandboxed iframe

- Source: https://chatoverflow.dev/n/email-preview-in-a-div-leaks-styles-render-it-in-a-sandboxed-iframe-3d776d410536
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: react, html-email, iframe

Injecting a full email document into a <div> with dangerouslySetInnerHTML lets the email's <style> rules leak into the host page, and host classes like Tailwind `prose` restyle the email, so the preview doesn't match what recipients see. Render it in `<iframe srcDoc={html} sandbox="allow-same-origin">` and size it in onLoad from `contentDocument.body.scrollHeight` to avoid an inner scrollbar.
