In traditional HTML, frames were used to divide a browser window into multiple sub - windows, each displaying a separate HTML document. There are two main types of frame - related elements in HTML:
<frameset>
: This element is used to define the structure of the frames on a page. It can have attributes like rows
and cols
to specify how the page is divided. For example, <frameset rows="20%,80%">
divides the page into two rows, where the first row takes up 20% of the height and the second row takes up 80%.<frame>
: This element is used within a <frameset>
to specify an individual frame. It has a src
attribute that points to the HTML document to be displayed in the frame. For example, <frame src="page1.html">
will display the content of page1.html
in the frame.In modern web development, CSS provides more flexible and responsive ways to create frame - like layouts. CSS Layout Modules such as Flexbox and Grid are commonly used to achieve this.
display
property to flex
, you can turn it into a flex container, and its direct children become flex items.Here is an example of using HTML frames:
<!DOCTYPE html>
<html>
<head>
<title>HTML Frames Example</title>
</head>
<frameset rows="20%,80%">
<frame src="header.html">
<frameset cols="20%,80%">
<frame src="sidebar.html">
<frame src="content.html">
</frameset>
</frameset>
</html>
In this example, the page is divided into two rows. The top row displays the content of header.html
, and the bottom row is further divided into two columns, showing sidebar.html
on the left and content.html
on the right.
<!DOCTYPE html>
<html>
<head>
<style>
.flex - container {
display: flex;
flex - direction: row;
height: 300px;
}
.flex - item {
flex: 1;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="flex - container">
<div class="flex - item">Item 1</div>
<div class="flex - item">Item 2</div>
<div class="flex - item">Item 3</div>
</div>
</body>
</html>
In this example, we create a flex container with three flex items. The flex - direction
property is set to row
, so the items are arranged horizontally. The flex: 1
property on the flex items makes them share the available space equally.
<!DOCTYPE html>
<html>
<head>
<style>
.grid - container {
display: grid;
grid-template - rows: 100px 200px;
grid-template - columns: 150px 350px;
}
.grid - item {
border: 1px solid black;
}
</style>
</head>
<body>
<div class="grid - container">
<div class="grid - item">Cell 1</div>
<div class="grid - item">Cell 2</div>
<div class="grid - item">Cell 3</div>
<div class="grid - item">Cell 4</div>
</div>
</body>
</html>
Here, we create a grid container with a 2x2 grid layout. The grid-template - rows
and grid-template - columns
properties define the size of the rows and columns respectively.
fr
unit to define flexible grid tracks.<header>
, <nav>
, <main>
, <aside>
, and <footer>
to make your code more readable and accessible. For example, instead of using a <div>
for the page header, use the <header>
element.Frames in HTML and CSS are powerful tools for creating structured and organized web page layouts. While HTML frames have their limitations and are less commonly used in modern web development, CSS Layout Modules such as Flexbox and Grid provide more flexible and responsive ways to achieve frame - like layouts. By understanding the fundamental concepts, usage methods, common practices, and best practices, you can create visually appealing and functional web pages that meet the needs of your users.