✔ HTML layout refers to the structural arrangement of elements on a webpage.
✔ It defines how content (text, images, navigation, footer, etc.) is displayed and organized.
✔ A proper layout ensures a user-friendly, responsive, and well-structured webpage.
HTML provides several semantic tags to create a structured layout:
Tag | Purpose |
---|---|
<header> |
Defines the top section of the webpage (logo, navigation, etc.). |
<nav> |
Contains the navigation menu (links to different sections/pages). |
<section> |
Represents a thematic grouping of content. |
<article> |
Contains independent content (e.g., blog post, news article). |
<aside> |
Holds sidebar content (ads, links, extra info). |
<main> |
Wraps the main content of the page (only one <main> per page). |
<footer> |
Defines the bottom section (copyright, contact, links). |
<div> |
A generic container for grouping elements (used for styling/layout). |
<span> |
A small inline container for styling specific text parts. |
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Website Layout</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Website Logo</h1>
<nav>
<a href="#">Home</a> |
<a href="#">About</a> |
<a href="#">Services</a> |
<a href="#">Contact</a>
</nav>
</header>
<main>
<section>
<h2>Main Content</h2>
<p>This is the main section of the webpage.</p>
</section>
<article>
<h2>Latest News</h2>
<p>This is an article about the latest updates.</p>
</article>
<aside>
<h3>Sidebar</h3>
<p>Additional links or ads go here.</p>
</aside>
</main>
<footer>
<p>© 2025 My Website. All rights reserved.</p>
</footer>
</body>
</html>
✔ This layout includes a header, navigation, main content, sidebar, and footer.
✔ CSS is used to style and position elements for a better layout.
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header, footer {
background: #333;
color: white;
text-align: center;
padding: 10px;
}
nav a {
color: white;
text-decoration: none;
margin: 0 10px;
}
main {
display: flex;
padding: 20px;
}
section {
flex: 2;
padding: 20px;
background: #f4f4f4;
}
aside {
flex: 1;
padding: 20px;
background: #ddd;
}
footer {
margin-top: 20px;
}
✔ This CSS makes the layout responsive and improves styling.
1️⃣ Using <div>
and CSS for Grid Layouts
✔ <div>
elements are used to structure layouts with CSS Grid or Flexbox.
✔ Example:
.container {
display: grid;
grid-template-columns: 1fr 3fr 1fr;
}
2️⃣ Using CSS Flexbox for Responsive Design
✔ Example:
.main-content {
display: flex;
flex-direction: row;
justify-content: space-between;
}
3️⃣ Using Bootstrap for Quick Layouts
✔ Bootstrap provides predefined layout classes for easy design.
✔ Example:
<div class="container">
<div class="row">
<div class="col-md-6">Left Side</div>
<div class="col-md-6">Right Side</div>
</div>
</div>
✅ Use semantic elements (<header>
, <nav>
, <main>
, etc.) for clarity.
✅ Make layouts responsive using CSS Grid, Flexbox, or frameworks like Bootstrap.
✅ Keep navigation clear and user-friendly.
✅ Use CSS for layout styling instead of inline styles.
✅ Test on different screen sizes to ensure mobile-friendliness.
HTML layout is essential for structuring content, improving readability, and enhancing user experience. Combining HTML structure with CSS techniques like Flexbox, Grid, or Bootstrap makes websites modern and responsive.