HTML Layout
ποΈ What is HTML Layout?
HTML layout refers to how elements are visually arranged on a webpage. A well-structured layout improves both usability and appearance. Itβs like planning the blueprint of a building β structure first, content second! π§±
>>βContent is king, but layout is the kingdom.β π
π§° Common Layout Techniques
- HTML5 Semantic Elements β Clean, accessible structure using tags like <header>, <nav>, <section>, etc.
- CSS Flexbox β 1D layout: align items horizontally or vertically
- CSS Grid β 2D layout: place items in rows and columns
- <div> Tag β Generic container, useful with classes and IDs
π§© HTML5 Semantic Layout Structure
Semantic HTML Layout Example
<header>
<h1>My Website</h1>
</header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#services">Services</a></li>
</ul>
</nav>
<main>
<section>
<h2>Welcome</h2>
<p>This is a simple layout.</p>
</section>
</main>
<footer>
<p>© 2025 My Website</p>
</footer>Note
π‘ Semantic tags help search engines and screen readers understand your content structure better!
π¦ Using <div> for Layout
Before semantic HTML, layouts were built mostly using <div> and CSS classes.
Layout Using divs
<div class="header">Header</div>
<div class="nav">Navigation</div>
<div class="main">Main Content</div>
<div class="footer">Footer</div>Note
β οΈ Use <div> only when no semantic element fits your need.
π― CSS for Layout Control
1οΈβ£ Flexbox Example
Flexbox Layout
.container {
display: flex;
flex-direction: row;
justify-content: space-between;
}2οΈβ£ Grid Example
Grid Layout
.grid {
display: grid;
grid-template-columns: 1fr 2fr;
gap: 20px;
}π Layout vs Styling
π Layout = positioning of elements
π¨ Styling = visual presentation (colors, fonts, borders)
π Semantic Layout Elements Overview
| Tag | Description |
|---|---|
| <header> | Defines the header for a page or section |
| <nav> | Contains navigation links |
| <main> | Represents the main content |
| <section> | Groups related content together |
| <article> | Self-contained content like blog posts |
| <aside> | Sidebar or related information |
| <footer> | Defines footer for page or section |
π Useful Resources
>>βA strong layout turns content into an experience.β π¨π§