How can I remove the border from iframe using HTML or CSS?
Suppose this is my iframe
<iframe src="url" width="500" height="300">text here</iframe>
as I would like to show this iframe in my web-page, which has different website URL, without the border it would look better and should match my website background color, so it can look like my websites webpage only
Thanks
You can easily do it using frameborder attribute of iframe, like code below
<iframe src="url" width="200" height="200" frameborder="0">
<p>Your browser does not support iframes.</p>
</iframe>
to make it work in all browsers including IE6 you can use frameBorder attribute ('B' is capital)
<iframe src="myURL" width="300" height="300" frameBorder="0" scrolling="no">Browser not compatible. </iframe >
Note: use frameBorder (capital B) for IE, otherwise will not work. But, the iframe frameborder attribute is not supported in HTML5. So, Use CSS instead.
<iframe src="/url" style="width: 100%; height: 400px; border: 0"></iframe>
you can also remove scrolling using scrolling attribute
<iframe src="http://example.org" width="200" height="200" scrolling="no" style="border:0">
Also, you can use seamless attribute which is new in HTML5.
The seamless attribute of the iframe tag is only supported in Opera, Chrome, and Safari.
If the above solutions doesn't work for you then you can try this CSS
.frameNoBorder {
padding:0px;
margin:0px;
border: 0px
}
This will work, thanks.
For more better output to remove iframe borders use "frameborder="0" hspace="0" vspace="0" marginheight="0" marginwidth="0"
"
So example
<iframe src="/url" width="100%" marginwidth="0" height="400" marginheight="0" scrolling="No" frameborder="0" hspace="0" vspace="0">Error, iFrame not supported </iframe>
If you have lots of iFrame in web-page and want to remove borders using Javascript, call this function on page load.
//remove border from all iFrame of page
function removeAllIFrameBorders(){
if (window.document.getElementsByTagName("iframe"))
{
var iFrameElements = window.document.getElementsByTagName("iframe");
for (var i = 0; i < iFrameElements.length; i++)
{
iFrameElements[i].frameBorder="0"; // For most browsers.
iFrameElements[i].setAttribute("frameBorder", "0"); // backup of above.
iFrameElements[i].contentWindow.document.body.style.border="none"; // For IE.
}
}
}
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly