Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are iframes inline-elements by default?

iframe = Inline?

While debugging some layout problem today I was surprised to see that <iframe> elements have a default display property of inline.

For me this seems strange, especially considering that you can apply a height and width to an <iframe> that is respected by the browser, which should not be the case for a simple inline-element.

So can anyone explain me the reasoning behind this?

Demo

HTML

<iframe id="test"></iframe>

CSS

alert($('#test').css('display'))

https://jsfiddle.net/0tdLr9pq/

Thanks!

like image 245
aKzenT Avatar asked Mar 09 '15 23:03

aKzenT


People also ask

Is iframe an inline element?

Definition and Usage. The <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.

Why inline frames are used?

An inline frame (iframe) is a HTML element that loads another HTML page within the document. It essentially puts another webpage within the parent page. They are commonly used for advertisements, embedded videos, web analytics and interactive content.

Are iFrames being deprecated?

IFrames are not obsolete, but the reasons for using them are rare. Using IFrames to serve your own content creates a "wall" around accessing the content in that area. For crawlers like Google, It's not immediately clear that cotent in an iframe will be ranked as highly as if the content were simply part of the page.

Are inline elements are normally displayed without starting a new line?

An inline element does not start on a new line. An inline element only takes up as much width as necessary.


2 Answers

Because the HTML4 spec said so:

The IFRAME element allows authors to insert a frame within a block of text. Inserting an inline frame within a section of text is much like inserting an object via the OBJECT element: they both allow you to insert an HTML document in the middle of another, they may both be aligned with surrounding text, etc.

The "be aligned with surrounding text" part means they shouldn't be block-level by default.

And it's true that, usually, inline elements ignore the height and width properties:

10.3.1 Inline, non-replaced elements

The width property does not apply.

10.6.1 Inline, non-replaced elements

The height property does not apply.

But that's not true for replaced elements, like iframe. This is explained in 10.3.2 and 10.6.2 sections.

like image 166
Oriol Avatar answered Sep 17 '22 10:09

Oriol


IFRAME stand for Inline Frame. See this : http://www.w3.org/TR/html401/present/frames.html#h-16.5

like image 24
Nyamiou The Galeanthrope Avatar answered Sep 20 '22 10:09

Nyamiou The Galeanthrope