HTML – Frames

By Published 2 min read

In HTML, frame elements are used to divide a web page into multiple sections or frames, each of which can display different content. Frames were more commonly used in earlier web development but have become less common in modern web design due to various issues and limitations. However, it’s still valuable to understand how they work.

Here are some key elements related to frames:

  1. <frameset> Element: This is the container element used to define the layout of frames on a web page. It’s typically placed within the <html> element and can have attributes like rows or cols to specify the dimensions and arrangement of frames.
  2. <frame> Element: This element is used within the <frameset> element to define individual frames. Each <frame> element has attributes like src to specify the content to be displayed in the frame and name to give the frame a unique identifier.
  3. <iframe> Element: While not exactly the same as frames, <iframe> elements are often used to embed external web content within a page. They are more versatile and widely used in modern web development.
  4. <noframes> Element: This is used within the <frameset> element to provide alternative content for browsers that do not support frames. It’s helpful for accessibility and SEO.

Here’s a basic example of using frames:

<!DOCTYPE html>
<html>
<head>
    <title>Frames Example</title>
</head>
<frameset cols="25%, 75%">
    <!-- Left Frame: Navigation Menu -->
    <frame src="menu.html" name="menu">
    
    <!-- Right Frame: Content -->
    <frame src="content.html" name="content">
    
    <!-- Provide alternative content for non-frame browsers -->
    <noframes>
        <body>
            This page uses frames. Your browser does not support frames.
        </body>
    </noframes>
</frameset>
</html>
Code language: HTML, XML (xml)

In this example:

  • We define a frameset with two columns using the cols attribute, with the left column taking up 25% of the width and the right column taking up 75%.
  • Two <frame> elements are used to specify the content for each frame. The src attribute indicates the source file to be displayed in each frame. For example, “menu.html” and “content.html” would be replaced with the actual filenames or URLs.
  • The name attribute is used to give each frame a unique name, which can be used for targeting links and forms to load content into specific frames.
  • Inside the <noframes> element, we provide an alternative message that is displayed for browsers that do not support frames. This message informs users that the page uses frames and that their browser does not support them.

Please note that frames are not commonly used in modern web development due to various limitations and compatibility issues. Instead, web developers typically use more flexible layout techniques such as CSS to achieve similar designs while maintaining better compatibility and accessibility.

It’s important to note that frames are not commonly used in modern web development due to several drawbacks, including issues with search engine optimization (SEO), bookmarking, and accessibility. Instead, developers often use CSS and more advanced layout techniques to achieve similar effects while maintaining better compatibility and performance.

Khan Waseem is a tech lead and full-stack engineer in Bengaluru, building hospitality and SaaS software with Node.js, React and React Native. See the resume