In the realm of web development, HTML is a tool that enables us to create and structure content on the World Wide Web. One of its many features is the ability to implement frames, which allow us to divide a webpage into smaller, distinct areas. These frames can then display different content or navigate independently. In this guide, we will delve into how to use frames in HTML, accompanied by practical examples.

Before we proceed, understanding that the use of frames in web design has largely been outdated due to their negative impact on accessibility, SEO, and responsive design. However, for historical or specific use cases, knowing how to use them can still be beneficial. Always consider modern web design practices when deciding to use frames.

The Basic Structure of an HTML Frame
An HTML frame consists of two main elements: the <frameset> tag and the <frame> tag. The <frameset> tag defines the number of frames, their size, and their respective positions within the webpage. The <frame> tag, on the other hand, specifies the content material of each frame.

Here's a simple example of an HTML page that uses two frames, side by side. The left frame is 30% of the webpage width, while the right frame takes up the remaining 70%.
Using the <frameset> Tag

The <frameset> tag is a container for the <frame> tags. You can specify the rows and columns properties to divide the webpage into frames. Here's how to use it:
<frameset cols="30%, 70%">
Using the <frame> Tag

The <frame> tag is used within the <frameset> tag to define each individual frame. You can specify the source of the content (src attribute), the name of the frame (name attribute), and more. Below is an example of two <frame> tags within a <frameset> tag:
<frame src="left_frame.html" name="leftFrame">
<frame src="right_frame.html" name="rightFrame">

Navigating Between Frames
You can navigate between frames using JavaScript. The following example shows how to switch from one frame to another:


















Let's assume you have two frames named "rightFrame" and "leftFrame". To switch content from "rightFrame" to "leftFrame", you wouldn't update the content of "rightFrame" directly:
document.rightFrame.location.href = "new_right_frame.html";
Instead, you update the content of "leftFrame" to reload "new_right_frame.html". This way, you're essentially making the navigation back to the "leftFrame" from the "rightFrame", leading to a more seamless transition. Here's how to accomplish this:
Creating a Navigation Function
First, create a navigation function in JavaScript that will handle switching frames. This function should take the frame name and the new source as parameters:
function navigate(framename, newsrc) {
document.getElementById(framename).src = newsrc;
}
Calling the Navigation Function
Then, in your HTML, you can create a button that calls this function:
<button onclick="navigate('leftFrame', 'new_right_frame.html')">Switch frames</button>
This way, when the button is clicked, the frames will switch without refreshing the entire webpage.
Targeting Frames in Links
Another common use of frames is displaying external content within an iframe. An iframe is an inline frame that displays another webpage within a webpage. Here's how you can make a link open in a frame:
To make a link open in a frame named "leftFrame", you need to specify this in the <a> tag's target attribute:
<a href="https://www.example.com" target="leftFrame">Visit Example</a>
This will open the linked webpage in the existing "leftFrame", overriding its current content.
Remember, using frames can lead to accessibility issues and search engine optimization challenges. Use them judiciously and only when absolutely necessary. Modern web design frameworks offer more accessible and SEO-friendly solutions for multi-part webpages. Always consider these factors when deciding to use frames.