HTML Page Layout Scripts
HTML page layout code: a responsive card layout, a HTML5 boilerplate page, and basic page layouts using div tags and a table.
Basic HTML Page layout using table tag
Before CSS was common, developers used <table> tags to place the header, menu, content and footer on a page. This is called a table layout. It still works, but it is not recommended today. This example is for learning and for understanding old websites.
Table layout code
<table width="100%" cellspacing="0" cellpadding="10" border="1">
<tr>
<td colspan="2" align="center"><h1>My Website</h1></td>
</tr>
<tr>
<td width="25%" valign="top">
<a href="#">Home</a><br>
<a href="#">About</a><br>
<a href="#">Contact</a>
</td>
<td valign="top">
<h2>Main Content</h2>
<p>This is the main area of the page.</p>
</td>
</tr>
<tr>
<td colspan="2" align="center">© 2025 My Website</td>
</tr>
</table>
Output in the browser:
How it works
- The first row has one cell that covers both columns (
colspan="2") for the header. - The second row has the menu on the left and the content on the right.
- The last row is the footer.
- Attributes like
width,align,valign,border,cellpaddingandcellspacingare old. In new code use CSS.
Learn more about tables in HTML Tables.
Basic HTML Page layout using Div tags
A page layout divides the page into parts like header, menu, content, sidebar and footer. The modern way is to use <div> tags (or semantic tags) with CSS Flexbox.
HTML and CSS code
<style>
* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; }
.header, .footer { background: #0073aa; color: #fff; padding: 15px; text-align: center; }
.menu { background: #333; }
.menu a { display: inline-block; color: #fff; padding: 12px 16px; text-decoration: none; }
.wrapper { display: flex; }
.content { flex: 3; padding: 15px; }
.sidebar { flex: 1; background: #f1f1f1; padding: 15px; }
@media (max-width: 600px) {
.wrapper { flex-direction: column; }
}
</style>
<div class="header"><h1>My Website</h1></div>
<div class="menu">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
<div class="wrapper">
<div class="content">
<h2>Main Content</h2>
<p>This is the main area of the page.</p>
</div>
<div class="sidebar">
<h3>Sidebar</h3>
<p>Links or ads go here.</p>
</div>
</div>
<div class="footer">© 2025 My Website</div>
Output in the browser:
How it works
.wrapperusesdisplay: flex, so the content and sidebar sit side by side.flex: 3andflex: 1give the content three times the width of the sidebar.- The media query stacks them on small phone screens.
Related: HTML Responsive Design and the older table layout.
HTML5 Basic Page Template (Boilerplate)
Every new web page starts with the same basic code. Save this HTML5 template and copy it whenever you start a new page.
HTML5 template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A short description of this page.">
<title>Page Title</title>
<link rel="icon" href="favicon.ico">
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Website Name</h1>
<nav>
<a href="/">Home</a>
<a href="/about/">About</a>
</nav>
</header>
<main>
<h2>Page Heading</h2>
<p>Page content goes here.</p>
</main>
<footer>
<p>© 2025 Website Name</p>
</footer>
<script src="app.js" defer></script>
</body>
</html>
What each part does
| Part | Why it is there |
|---|---|
<!DOCTYPE html> | Standards mode in the browser |
lang="en" | Language of the page, for screen readers and search engines |
charset | Shows all characters correctly |
viewport | Makes the page work well on phones |
description | Text that search engines may show under the title |
link and script | Connect your CSS and JavaScript files |
header, nav, main, footer | Semantic layout of the page |
Learn each part in HTML Page Structure.
HTML Responsive Card Layout
Cards are boxes with a title, a short text and a link. They are used for blog posts, products and services. This layout uses CSS Grid, so the cards fit the screen automatically, with no media query.
HTML and CSS code
<style>
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 16px;
font-family: Arial, sans-serif;
}
.card { border: 1px solid #ddd; border-radius: 6px; padding: 16px; }
.card h3 { margin-top: 0; }
</style>
<div class="cards">
<div class="card">
<h3>HTML</h3>
<p>Learn the structure of web pages.</p>
<a href="/learn/html/">Read more</a>
</div>
<div class="card">
<h3>CSS</h3>
<p>Style your pages and make them responsive.</p>
<a href="/learn/css/">Read more</a>
</div>
<div class="card">
<h3>JavaScript</h3>
<p>Add behaviour to your pages.</p>
<a href="/learn/javascript/">Read more</a>
</div>
</div>
Output in the browser:
How it works
display: gridmakes the container a grid.repeat(auto-fit, minmax(220px, 1fr))means: make as many columns as fit, each at least 220 pixels wide, and share the extra space equally.- On a phone the cards come one below another, and on a laptop three in a row.
Related: HTML Responsive Design.