0

So is there any difference in this:

<iframe src="iframe.html" width="100" height="100"></iframe>

and this:

<iframe src="iframe.html" style="width: 100px; height: 100px;"></iframe>

Both are supported in HTML5 and I wonder which one is better/reccomended? Any suggestions?

PowerUser
  • 812
  • 1
  • 11
  • 32
  • This is pretty much a personal preference, although I always try to stick with a CSS solution when I can... – Dryden Long Apr 02 '14 at 21:48
  • i think theres a difference when you manipulate the attributes after site has loaded theres no effect, but manipulation on css will resize – john Smith Apr 02 '14 at 21:48
  • @Dryden Long maybe you're right. That's the first thing that came to my mind. @ john Smith what do you mean? – PowerUser Apr 02 '14 at 21:55
  • Use CSS to style the – HddnTHA Apr 02 '14 at 21:51

3 Answers3

1

In that case I would suggest to use inline, like for

<iframe src="iframe.html" width="100" height="100"></iframe>

Because if css doesn't load properly or was disabled by user the container size will be the same. And it will be good for avoiding a block jumping effect.

Ju-v
  • 362
  • 3
  • 15
0

Like Dryden mentioned its really personal preference. I tend to stick with using class's in my style sheet rather than mixing in with html. Seems much cleaner to me. However, putting styling at element level would mean that you cannot cache the CSS style rules separately. Usually putting styles in CSS files would allow the caching to be done, thus reducing the amount of load from the server each time you load a page.

JayD
  • 6,173
  • 4
  • 20
  • 24
0

From the W3C:

"The separation of HTML from CSS makes it easier to maintain sites, share style sheets across pages, and tailor pages to different environments. This is referred to as the separation of structure (or: content) from presentation."

However, there can be exceptions to this. If you have an "original version" of what the page should look like, you can leave the width and height attributes in the markup. You can then use a CSS stylesheet to override the original height and width. This can make sense in the case of an img tag. See the following question: Should image size be defined in the img tag height/width attributes or in CSS?

Community
  • 1
  • 1
dgp
  • 953
  • 1
  • 8
  • 11
  • Yeah, maybe I will use both CSS and inline HTML markup for this - since it's allowed by the Standards it will validate. – PowerUser Apr 02 '14 at 22:02