Page Layout in HTML


HTML layout refers to the way in which elements are arranged on a webpage.

It involves the use of various HTML elements and CSS to structure and style content, ensuring that it is displayed in an organized and visually appealing manner.

 

Common Elements Used in HTML Layout

  1. <header>: Defines a header for a document or a section.
  2. <nav>: Defines a set of navigation links.
  3. <section>: Defines a section in a document.
  4. <article>: Defines independent, self-contained content.
  5. <aside>: Defines content aside from the content it is placed in (like a sidebar).
  6. <footer>: Defines a footer for a document or a section.
  7. <div>: Defines a division or a section in an HTML document, often used as a container for other elements.

 

Example of a Basic HTML Layout

Below is an example of a simple HTML layout for a blog page

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Blog</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
        }
        header, footer {
            background-color: #333;
            color: white;
            text-align: center;
            padding: 1em 0;
        }
        nav {
            background-color: #444;
            color: white;
            text-align: center;
            padding: 1em 0;
        }
        nav a {
            color: white;
            margin: 0 1em;
            text-decoration: none;
        }
        .container {
            display: flex;
            flex-wrap: wrap;
            margin: 2em;
        }
        .main {
            flex: 3;
            padding: 1em;
        }
        .aside {
            flex: 1;
            padding: 1em;
            background-color: #f4f4f4;
        }
        .article {
            background-color: #e2e2e2;
            padding: 1em;
            margin-bottom: 1em;
        }
    </style>
</head>
<body>

<header>
    <h1>My Blog</h1>
</header>

<nav>
    <a href="#">Home</a>
    <a href="#">About</a>
    <a href="#">Contact</a>
</nav>

<div class="container">
    <div class="main">
        <section class="article">
            <h2>Blog Post 1</h2>
            <p>This is the first blog post content.</p>
        </section>
        <section class="article">
            <h2>Blog Post 2</h2>
            <p>This is the second blog post content.</p>
        </section>
    </div>
    <aside class="aside">
        <h2>About Me</h2>
        <p>This is some information about the blog author.</p>
    </aside>
</div>

<footer>
    <p>&copy; 2024 My Blog</p>
</footer>

</body>
</html>

Example Explanation -

  1. <header>: Contains the main title of the blog.
  2. <nav>: Contains navigation links for the website.
  3. .container: A flex container that wraps the main content and the sidebar.
  4. .main: The main content area that holds multiple blog posts.
  5. .aside: A sidebar containing additional information, such as the author bio.
  6. <footer>: Contains the footer information.

 

CSS Layout Techniques

The example uses basic CSS for layout:

  • Flexbox: The .container uses flexbox to create a flexible layout that adjusts the main content and sidebar.
  • Background Colors and Padding: Used to visually separate different sections.

This layout ensures that the content is structured and easily navigable, providing a good user experience.