The marginheight attribute on an <iframe> set the space, in pixels, between the frame’s content and its top and bottom 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 marginwidth for left/right space.
Deprecated / obsolete.
Authors must not rely on marginheight. Learn it to recognize legacy markup; space embedded content with CSS instead.
Syntax
HTML Syntax
syntax.html
<iframe marginheight="pixels">…</iframe>
Modern equivalent: style the framed page’s body (or use srcdoc with CSS) for top/bottom 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 top and bottom internal space
Control CSS, not the attribute. The slider updates body margin in srcdoc.
Avoid marginHeight. The legacy IDL property mirrors the deprecated attribute.
Visible feedback. The label shows the current pixel value.
Same idea for width. Use horizontal CSS instead of marginwidth.
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. marginheight 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
marginwidth is also deprecated
Left/right internal space used marginwidth. 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 marginheight “for older browsers.” Use CSS and delete the obsolete attribute.
Compatibility
Browser Support
marginheight is a deprecated HTML attribute on iframe. Do not use it for new layouts.
✓ Deprecated · Prefer CSS
marginheight
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*
marginheightDeprecated for authors
Bottom line: *Do not ship marginheight. Space framed content with CSS (body margin/padding or srcdoc styles).
Remember
Key Takeaways
Role: old top/bottom 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:marginwidth, frameborder, scrolling — use CSS.
One line: drop marginheight — put top/bottom space in the framed page’s CSS.
Frequently Asked Questions
On an iframe, marginheight set the space in pixels between the frame’s content and its top and bottom borders — an internal vertical 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. marginheight was meant to space content inside the frame, next to its top and bottom edges.
The companion deprecated attribute for left and right internal space. Use CSS horizontal 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-top / margin-bottom } or padding. With srcdoc, put that CSS inside the embedded HTML.