HTML Tutorials‎ > ‎


What Are Frames?

Frames are kinda different from anything done in html in that you are not making a page in the traditional sense. What you are making is a template where you can put more than one page. Here's an example using TABLE commands:

 Page_1 Page_2

Above is a simple table. Read about tables in the Tables Tutorial. In fact, I would strongly urge you to read it first. This will be easier to understand if you do so. Now imagine that the table above is the entire viewing screen of your browser. frames are used to do just that, break up the screen. Other pages go in the frame cells. frames allow you to display more than one page at the same time, in the same screen.

If that table above were a browser screen using frame commands, there would be 3 pages involved: The frames page that breaks up the page and "Page1.htm", "Page2.htm".

The frame commands that would create a page like the example above would look like this:<frameset cols="50%,50%"><frame src="PAGE_1.htm"><frame src="PAGE_2.htm"></frameset>

Basic frame Commands
Neat, huh? There's two pages displayed at the same time. You simply split the screen into two parts and placed a different page in each part. Look again at the HTML frames code above; here's what's going on: frameset starts any frame page. It alerts the browser that frameS are going here. cols denotes that I want columns. In this case, I want two; each 50% of the screen.

Can you do other percentages? Of course you can. Just separate the percentages by commas and get it all to add up to 99% or 100%. 99%?! Yes. You see, 33%, 33%, 33% adds to 99 and splits the screen three ways. The browser just distributes the final 1% over the three spaces. frame src denotes the source of the frame. frames read the way you do, from left to right. The first source offered will be the left. I only have two frame sections so I need only 2 sources.</frameset> ends the whole thing.

Some Quick Questions:
Q: Do I have to write pages skinny enough to fit in only one-half of the page frame?
A: No. The browser will cram it all in the page, but it tends to look smashed. I'll offer examples in a moment.

Q: What if my page is taller than the screen? How do I put in a vertical scroll bar?
A: The browser will do it for you.

Q: Can I get rows too?
A: Yup. Here's how you do it...


Here's the frames code I'll use to do it:

<frameset rows="75%,25%"> <frame src="Page1.htm"><frame src="Page2.htm"> </frameset>

What is Happening Here?

Remember that frames read left to right like you. I told the browser I wanted frames by using the frameset command. I then broke up the page horizonally, instead of vertically, as before. Naming Cells and Using Targets.

Now we know how to break up the screen through frameset percentage commands. Now, to control page changes (links) in your frames. There are 3 basic methods of changing pages within frames:
  1. Click on a link in a frame - just that frame changes.
  2. Click on a link in a frame - another frame on the screen opens the page.
  3. Click on a link in a frame - the frames disappear and you get a regular page.
Here's how you do all three!
  • Click on a link in a frame - just that frame changes pages. This is the default. It just happens without you doing anything extra. So, if that's all you want to do, you already know what you need. Browsers are programmed to handle frame clicks this way. The other two methods require a little more coding.
  • Click on a link in a frame - another frame on the screen receives the information.
Now it's time to discuss 2 new commands, "NAME" and "TARGET." Let's say I'm doing a very simple frame page with only three frames. It'll look something like this:


In order for me to ask the browser to send info to another frame, I have to make a point of naming each of the frames. Name them whatever you wish, but keep it simple.

Here's what the frameset command will look like, with NAMES:

<frameset><frameset rows="50%, 50%"><frame name="A" src="cell_1.htm"><frame name="B" src="cell_2.htm"><frame name="C" src="cell_3.htm"></frameset>

Okay, great... you've named the cells. See the "NAME=" attributes I put in the frame src tags above? Good. Now that you have the frames named, you can make any link inside of them targeted. Basically, you're going to add a TARGET attribute to the usual <a href>.

Let's say this example link is in cell a above:
<a href="" target="C">

You can guess what will happen. When you click on the link, cell a will remain the same and cell c will open the page.

Leaving a frames Page Completely
So now you can send information from any frame to any frame. The problem is you're still on the frames page -- and some of the larger pages are squished.

Say you want to have someone click on a frame and have the link to pop up as its own page, in a full browser window. Well, you have to tell the browser to do that. Remember, the default is to have the page stay in the same frame. You need to target the link to open by itself. Simple enough. Just follow the format above but make the target, "_top." Note the underline before the word "top." It looks like this:<A HREF="" target="_top">

Encountering Non-frames-Ready Browsers
That's a problem. Most browsers today accept frames, but some still don't, text-only browsers for example. The "frames-challenged" will get an error code if they attempt to log on to a page with frames. Either that or they'll get a blank page. There's a few ways around it.
  • Don't do frames.
  • Write a page without any frames and offer a choice to go to a framed page or to a non-framed page.That means you have to write two pages.
  • Use <noframe> and </noframe> commands.
More about the noframe command: It's simple. You write a basic frame page like any of the three above -- but -- immediately following the first frameset command you put in a <noframe> command and write a message to the frames challenged.

Like so: <frameset cols="50%,50%"><noframe>The page you are attempting to enter uses frames. Click <A HREF="page.html">Here</A> for a non-frames version of this page.</noframe><frame src="PAGE_A.htm"><frame src="PAGE_B.htm"></frameset>

Hope This Helps! The person, whose browser can't see frames, gets the message and the person who can read frames will get the frames page. You know, you could just put the HTML code in there rather than a message. That way, the user would see the page and never know. I hope this has helped some, Happy Web Building!