CHAPTER 67

CSS Flexbox Introduction

Learn the fundamentals of Flexbox for creating one-dimensional layouts.

01. What is CSS Flexbox Introduction?

Flexbox is a CSS layout system for arranging items in rows or columns.
A flex container controls the layout of its flex items.
Flexbox makes alignment and spacing easier.

02. Syntax

.container { display: flex; }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>

.container {
    display: flex;
    gap: 15px;
}

.item {
    flex: 1;
    padding: 25px;
    background: #dbeafe;
}

</style>
</head>
<body>

<div class="container">

    <div class="item">HTML</div>
    <div class="item">CSS</div>
    <div class="item">JavaScript</div>

</div>

</body>
</html>

04. Important Points

✓ display: flex creates a flex container.
✓ Flex items are the direct children.
✓ Flexbox works along a main axis and cross axis.
✓ gap can create consistent spacing.

05. Common Mistakes

⚠ Applying flex properties to the wrong element.
⚠ Confusing container properties with item properties.
⚠ Forgetting mobile behavior.

06. Real World Use

Flexbox is used for navigation bars, cards, buttons, toolbars and responsive components.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Flex Row

Create three equal boxes using display: flex and flex: 1.