HTMLHard
How do you embed third-party content in an <iframe> safely?
By FrontendPro Editorial Team Updated 8/14/2026
#html#security#iframe
Answer
html
<iframe
src="https://example.com/widget"
sandbox="allow-scripts"
referrerpolicy="no-referrer"
loading="lazy"
title="Payment widget"></iframe>
- An empty
sandboxblocks everything; grant capabilities one at a time. Never combineallow-scripts allow-same-originfor untrusted content - the frame can then remove its own sandbox. - Talk to it via
postMessageand always checkevent.origin. - Protect your own page from being framed with
Content-Security-Policy: frame-ancestors 'self'. titleis required for screen readers.
