Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Flexbox Layout | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 19 of 55

·HTML

Flexbox Layout

10 min

Course progress35%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Creating a flex container (`display:flex`) and changing the flex direction
  • Main‑axis and cross‑axis alignment with `justify-content` and `align-items`
  • Flex item growth/shrink using the `flex` shorthand and `flex-basis`
  • Spacing with the modern `gap` property
  • Re‑ordering items with `order` for responsive layouts
  • Flexbox – One‑Dimensional Layout

    .container {
      display: flex;
      flex-direction: row;   /* row (default) or column */
      justify-content: space-between; /* main‑axis alignment */
      align-items: center;   /* cross‑axis alignment */
      flex-wrap: wrap;      /* allow items to wrap */
      gap: 1rem;           /* spacing between items */
    }
    
    • flex-direction – row (default) or column.
    • justify-content – Aligns items on the main axis (flex-start, center, space-around, space-between).
    • align-items – Aligns items on the cross axis (stretch, flex-start, center).
    • flex shorthand (flex: 1 0 auto) controls growth, shrink, and basis.
    • gap – Modern spacing property; replaces margin tricks.

    Example: Navigation bar

    <nav class='nav'>
      <a href='#'>Home</a>
      <a href='#'>About</a>
      <a href='#'>Contact</a>
    </nav>
    
    .nav { display: flex; gap: 1rem; }
    

    Advanced tricks

    • order – Re‑order items for different breakpoints without changing HTML.
    • flex-basis – Set the default size before growing/shrinking.
    • align-self – Override the container’s align-items for a single child.

    Quick checklist for Flexbox

    1. display:flex applied to a container? ✅
    2. Main‑axis (justify-content) and cross‑axis (align-items) set intentionally? ✅
    3. gap used instead of margins where possible? ✅
    4. order used for responsive re‑ordering? ✅

    Tip: Use the Flexbox Inspector in Chrome DevTools to visualise flex lines and item distribution.

    Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
    Previous lessonResponsive Design – Meta Viewport and Media QueriesContinue to lesson 20CSS Grid LayoutBack to HTML Course curriculum