Unit 2: Layout Systems & Flow ControlLesson #5 / 8

Lesson 5: CSS Flexbox Layouts, Alignment & Direction

Er. Manoj Kumar — AuthorEr. Manoj KumarLast Updated: 26 Aug, 2026

1. Flexbox 1-Dimensional Layout Engine

Flexbox (display: flex) provides a 1-dimensional layout system to distribute space, align items, and manage responsive direction along a Main Axis and a Cross Axis.

  • justify-content: Aligns items along the Main Axis (flex-start, center, space-between, space-around, space-evenly).
  • align-items: Aligns items along the Cross Axis (flex-start, center, flex-end, stretch).
  • flex-direction: Sets main axis direction (row, column, row-reverse, column-reverse).
  • flex-wrap: Controls wrapping behavior (nowrap, wrap).
  • HTML5 Web Code (index.html)
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Flexbox Alignment Studio</title>
    <style>
    body {
    background-color: #17181c;
    color: #ffffff;
    font-family: Arial, sans-serif;
    padding: 30px;
    }
    .flex-navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #1f2029;
    padding: 16px 24px;
    border-radius: 12px;
    border: 1px solid #333;
    }
    .nav-links {
    display: flex;
    gap: 16px;
    list-style: none;
    }
    .nav-links a {
    color: #04AA6D;
    text-decoration: none;
    font-weight: bold;
    }
    .flex-grid {
    display: flex;
    gap: 16px;
    margin-top: 24px;
    flex-wrap: wrap;
    }
    .flex-item {
    flex: 1 1 200px;
    background-color: #242632;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    border-top: 3px solid #04AA6D;
    }
    </style>
    </head>
    <body>
    <nav class="flex-navbar">
    <h2>Nextsem</h2>
    <ul class="nav-links">
    <li><a href="#">Home</a></li>
    <li><a href="#">Courses</a></li>
    <li><a href="#">Projects</a></li>
    </ul>
    </nav>
    <div class="flex-grid">
    <div class="flex-item">Box 1</div>
    <div class="flex-item">Box 2</div>
    <div class="flex-item">Box 3</div>
    </div>
    </body>
    </html>

    Interactive Knowledge Check

    Test your understanding of Lesson #5 concepts

    Which Flexbox property centers child items along the cross axis (vertical in row direction)?