Remove border from IFrame
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If an embedded iframe shows an unwanted border, the modern fix is usually just CSS. In current HTML and CSS practice, border: 0 or border: none is the correct approach, while older HTML attributes such as frameborder="0" exist only for legacy compatibility.
The Modern CSS Fix
For one specific frame, inline CSS works:
For a reusable solution, put the rule in a stylesheet:
That is the preferred approach because it keeps presentation in CSS rather than in the markup.
Why frameborder="0" Is Not the Best Answer
Older code often uses:
This still appears in old snippets and may still work in browsers, but it is obsolete in modern HTML. If you are maintaining existing markup, leaving it in place may be harmless, but new code should use CSS.
When the Border Is Not Actually on the iframe
Sometimes the visible line is not the frame border at all. It may come from:
- A border on the parent container
- A browser default outline
- A gap caused by inline layout or background contrast
If border: 0 does not appear to work, inspect the element in browser dev tools and confirm where the line is coming from.
For example, this container would still show a visible frame-like border even if the iframe itself had no border:
Make Embedded Frames Look Cleaner
If you want the embedded content to sit flush with the surrounding layout, it also helps to control display and sizing:
display: block removes inline-element spacing surprises and often produces a cleaner layout when the frame fills a card or section.
Accessibility and Security Still Matter
Removing the border is only a visual concern. You should still provide a useful title so assistive technology can identify the embedded content.
Also remember that iframes have security implications unrelated to styling. Depending on the use case, attributes such as sandbox, allow, or referrerpolicy may matter more than the border styling itself.
Styling Across Many Frames
If the site contains several embed types, use classes rather than styling every iframe globally. A global iframe { border: 0; } rule is simple, but it can accidentally affect admin tools, third-party widgets, or embeds that were supposed to keep a visible boundary.
A class-based rule keeps intent clear and avoids unintended design regressions.
Common Pitfalls
The biggest mistake is relying on frameborder="0" as if it were the modern standard. It is legacy markup; CSS is the proper solution in current code.
Another issue is assuming the line you see is definitely the frame border. Quite often it is the container, outline, or surrounding layout.
Developers also forget to add a title when focusing only on appearance. Removing the border should not make the embed less accessible.
Finally, avoid broad global CSS rules unless you truly want every iframe on the site to be borderless.
Summary
- Use CSS such as
border: 0orborder: noneto remove iframe borders. - Prefer classes or stylesheets over obsolete
frameborder="0"markup. - If the line remains, inspect the container and surrounding layout, not just the iframe itself.
- Use
display: blockand explicit sizing when you want a flush embedded layout. - Keep accessibility and security attributes in place even when the visual change is small.
Related reading
- Remove duplicate objects from an array using javascript
- Remove element by id
- Remove empty array elements
- Remove empty elements from an array in Javascript
- remove grey background on link clicked in ios safari / chrome / firefox
- Remove HTML tags from a String
- Remove HTML Tags from an NSString on the iPhone
- Remove iOS input shadow
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.