Chapter 22: HTML & CSS Layout

HTML & CSS: Layout

Until now we mostly talked about single elements — colors, typography, box model, selectors… Now we talk about how to arrange many elements together on the page so that everything looks intentional, balanced, beautiful, and works nicely on mobile too.

Layout = the art of deciding where each piece goes, how big it is, how it behaves when the window size changes, and how elements relate to each other.

In 2026 there are mainly three modern layout systems you should know (in order of learning priority):

  1. Normal Flow + Block vs Inline (the default behavior — you must understand this first)
  2. Flexbox (1-dimensional layout — rows OR columns — most used day-to-day)
  3. Grid (2-dimensional layout — rows AND columns — perfect for page structure)

We will go very detailed, step by step, like I’m teaching you offline with a whiteboard.

1. Normal Flow – The Default Layout (You Must Master This First)

When you write HTML without any CSS layout tricks, the browser uses normal flow (also called block formatting context).

Rules of normal flow:

Display value (default) Behavior Takes full width? New line? Examples
block Starts on new line, takes full available width Yes Yes <div>, <p>, <h1>–<h6>, <section>, <article>, <header>, <footer>
inline Flows inside line, only as wide as content No No <span>, <a>, <strong>, <em>, <img> (default)
inline-block Like inline but respects width/height/padding No No <img>, <button> (often set manually)

Quick test — copy this HTML:

HTML
CSS

Result: blocks stack vertically, inline elements stay side-by-side like words in a sentence.

2. Flexbox – The Hero of Everyday Layout (Most Important to Learn First)

Flexbox is perfect when you want to arrange items in one direction (row or column) and want powerful alignment & distribution control.

Golden parent rule:

CSS

Most useful flex properties (put on parent):

Property Common values What it does
flex-direction row (default), column, row-reverse Main axis direction
justify-content flex-start, center, space-between, space-around, space-evenly Distributes space on main axis
align-items stretch (default), center, flex-start, flex-end, baseline Aligns items on cross axis
gap 20px, 2rem, 1em 2em Space between items (replaces margin hacks)
flex-wrap nowrap (default), wrap, wrap-reverse Allow items to wrap to next line

Most useful on child items:

  • flex: 1 or flex: 0 1 auto → grow & shrink
  • flex-grow, flex-shrink, flex-basis
  • align-self → override parent align-items for one child

3. Real Layout Example – Hero + Cards + Footer (Flexbox + Normal Flow)

index.html

HTML

style.css

CSS

What You Should See & Play With

  • Header: logo left, nav right → justify-content: space-between
  • Hero: everything perfectly centered vertically & horizontally → flex-direction: column + align-items: center
  • Cards: 3 cards side-by-side on desktop → wrap to new row on mobile → flex-wrap: wrap + flex: 1 1 300px
  • Resize browser window → watch cards adapt automatically

Quick Layout Mastery Path (2026 Order)

  1. Master normal flow + block vs inline vs inline-block
  2. Master Flexbox (95% of day-to-day layouts)
  3. Learn CSS Grid (for full-page layouts, dashboards, galleries)
  4. Media queries → make everything responsive
  5. Position (relative/absolute/fixed/sticky) — use only when Flex/Grid can’t solve

How does the page behave when you make the browser narrow? Cards stacking nicely? Header still readable?

Next steps — tell me what you want next:

  • “Flexbox deep dive with 10 real examples”
  • “CSS Grid crash course”
  • “Make this layout fully responsive with media queries”
  • “Positioning – relative vs absolute vs fixed”
  • “Common layout bugs & how to fix them”

You’re now entering the real power zone of CSS. Chai khatam? Fresh cup lao — let’s keep building! 🚀 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *