The marginwidth attribute on an <iframe> set the space, in pixels, between the frame’s content and its left and right borders.
MDN lists it under deprecated iframe attributes: do not use it in new content. Prefer CSS on the embedded document (for example body margin) or padding you control via srcdoc. Pair historically with marginheight for top/bottom space.
Deprecated / obsolete.
Authors must not rely on marginwidth. Learn it to recognize legacy markup; space embedded content with CSS instead.
Syntax
HTML Syntax
syntax.html
<iframe marginwidth="pixels">…</iframe>
Modern equivalent: style the framed page’s body (or use srcdoc with CSS) for left/right spacing — not presentational attributes on the iframe.
Values
Attribute Values
Historical values (do not use in new work):
Value
Description
Try it
pixels
Non-negative integer for left and right internal space
Control CSS, not the attribute. The slider updates body margin in srcdoc.
Avoid marginWidth. The legacy IDL property mirrors the deprecated attribute.
Visible feedback. The label shows the current pixel value.
Same idea for height. Use vertical CSS instead of marginheight.
Edge Cases & Pitfalls
Most confusion comes from mixing internal frame spacing with CSS margin on the iframe itself.
inside vs outside
Not iframe CSS margin
iframe { margin: … } offsets the frame in the parent layout. marginwidth targeted space inside the frame around its content.
origin
Cross-origin limits
You cannot restyle another origin’s document from the parent page. Spacing must come from that page’s own CSS (or from content you embed with srcdoc).
pair
marginheight is also deprecated
Top/bottom internal space used marginheight. Replace both with CSS; do not keep one attribute alone.
a11y
Always set title
Spacing attributes never replaced an accessible name. Give every iframe a clear title.
migrate
Remove, don’t stack
Do not keep marginwidth “for older browsers.” Use CSS and delete the obsolete attribute.
Compatibility
Browser Support
marginwidth is a deprecated HTML attribute on iframe. Do not use it for new layouts.
✓ Deprecated · Prefer CSS
marginwidth
MDN: deprecated on iframe. Engines may still recognize it for legacy pages, but authors must use CSS on the embedded content instead.
LegacyNot for new work
Google ChromeLegacy parse*
Deprecated*
Mozilla FirefoxLegacy parse*
Deprecated*
Apple SafariLegacy parse*
Deprecated*
Microsoft EdgeLegacy parse*
Deprecated*
OperaLegacy parse*
Deprecated*
Samsung InternetLegacy parse*
Deprecated*
Internet ExplorerLegacy era
Legacy*
marginwidthDeprecated for authors
Bottom line: *Do not ship marginwidth. Space framed content with CSS (body margin/padding or srcdoc styles).
Remember
Key Takeaways
Role: old left/right space inside an <iframe> — now deprecated.
Replace with: CSS on the embedded body (or controlled srcdoc).
Not outer margin: iframe CSS margin is a different layout idea.
Also drop:marginheight, frameborder, scrolling — use CSS.
One line: drop marginwidth — put left/right space in the framed page’s CSS.
Frequently Asked Questions
On an iframe, marginwidth set the space in pixels between the frame’s content and its left and right borders — an internal horizontal margin for the embedded document.
No. MDN and HTML mark it deprecated/obsolete. Prefer CSS on the embedded page (body margin) or spacing you control via srcdoc / the framed document.
No. CSS margin on the iframe moves the frame in the parent page. marginwidth was meant to space content inside the frame, next to its left and right edges.
The companion deprecated attribute for top and bottom internal space. Use CSS vertical margin or padding on the embedded content instead.
Historically iframe (and legacy frame). Do not use it on new pages.
If you control the framed document, set body { margin-left / margin-right } or padding. With srcdoc, put that CSS inside the embedded HTML.