Iframe question


I want to put an iframe into my web page.
Is there a way I can only have it display a portion of the
iframe src url?

For example, I don’t want the left and right side navigation panes,
only the middle portion.

<iframe src=“http://mysite.com” frameborder=“0” width=“800” height=“1000” scrolling=“auto”></iframe>


Is the iframe source on your site or someone else’s?

If it’s on your site, can you not recode it somehow so that the section is there as a stand-alone page as well as a full page with navigation?

Of course, there’s still the question of why you’re using iframes, which are not generally a good answer to any question…

You could put the iframe in a div that is smaller than the iframe and use overflow:hidden on the div to hide the excess. Then just drag the iframe to the side to reveal only the middle section.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#iframe {
    border:10px solid red;
#iframe iframe {
<div id="iframe">
    <iframe src="http://www.pmob.co.uk/"></iframe>

Of course iframes should be avoided if at all possible. (And if you are viewing a site not belonging to you in the iframe then you probably need their permission).

If the source is on one of your sites, there are many better ways of doing this. If not, you probably shouldn’t be doing it at all.

These responses…

…bring up a question a question that has bugged me for a while.

What’s wrong with <frames> and <iframes> ?

When I first started learning a few years ago, all I read was don’t use <frames> use <iframes> instead.

Now I’m reading here, don’t use <iframes> either.

Why not?

I play an on-line fantasy RPG that started out using <frames> and now I see that the he has switched to <iframes>. Both work/worked great, so that makes me really wonder “what’s wrong with them?”

I’m asking because I’ve seen their use put down without explanation. Just avoid them.


Frames (be it frameset OR iframe) are an accessibility failure. Many screen readers will fail to read their content, they usually break keyboard navigation, it prevents people from directly linking to content, the contents of the frame are treated separately from the actual page link by search engines, it requires more handshakes to the server which can usually mean slower loading pages despite any reduction in bandwidth – and it can often use MORE bandwidth since the content of each separate section is accompanied by an extra HEAD.

The same can be said for DHTML and AJAX when it comes to delivering content – A dearly departed friend of mine called AJAX when used for things like tabs “The new framesets” – and that was NOT meant as a compliment.

The reasons to use them are often outweighed by the reasons not to. If you practice semantic markup, separation of presentation from content, and build/include your markup’s static bits server-side (php, asp, shtml for example), everything else on the page should be cached and that extra two or three k on the page load really shouldn’t have an impact with everything else cached.

Of course, if you aren’t practicing modern coding techniques and have 20k to 50k of static markup for a template without the actual content in it, you won’t understand a word of the above…

Which is what makes it funny when things like frames, iframes, DHTML and AJAX are touted as bandwidth savers by people using 100k of HTML to deliver 5k of content – basically the same people who vomit up pages any-old-way then practice white-space stripping to obfuscate their ineptitude.

NOT to say I’m singling you out for that - “your first page” is fairly lean and a decent attempt – it does have SOME issues, but as a first page you’re already light-years ahead of many people who’ve been at it for years. I mean you issues are minor – multiple H1’s, H3’s around non-heading elements, DIV id=“header” around what SHOULD BE your H1, H3’s without the preceding H2, nonsensical heading tag orders, some unnecessary classes and DIV, non-breaking spaces used to handle formatting, as well as a handful of design issues like alpha transparency on the backgrounds making it painful to scroll in Firefox on anything less than a quad core machine…

As a “first out” that’s still not bad.

Usually the main reason for not using them is that there are much better and more accessible solutions. More info here and [URL=“http://webaim.org/techniques/frames/”]here. Iframes can also pose security problems so a number of users will have them switched off anyway to avoid the results of iframe injection attacks which can happen to sites that you may trust.

Thanks for the info both of you.

After reading the part about the screen readers, it makes me wonder what our Game Master does to his pages. We have many blind players that don’t have any problem. In fact, on the games home page, he has a link for suggestions on how to improve the game for the blind.

Again, thanks for the info.