Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

Flexbox Introduction

Flexbox Introduction

CSS CODES & EXAMPLES

CSS Flexbox Introduction

Learn the fundamentals of CSS Flexbox and how to create flexible, responsive layouts with rows, columns, alignment, spacing and distribution.

01

What is CSS Flexbox?

A modern one-dimensional layout system

Flexbox, short for Flexible Box Layout, is a CSS layout system designed to arrange elements in a row or column. It makes alignment, spacing and responsive layouts much easier to manage.

Flexible

Items can grow and shrink according to available space.

Responsive

Flexbox works well with different screen sizes.

Alignment

Items can be aligned horizontally and vertically.

Spacing

Space between items can be controlled easily.

02

display: flex

Create a flex container

To start using Flexbox, apply display: flex; to the parent element. Its direct children automatically become flex items.

display-flex.css
.container {
  display: flex;
}
ITEM 1
ITEM 2
ITEM 3
03

Flex Container and Flex Items

Understand the parent-child relationship

The element with display: flex becomes the flex container. Its direct children become flex items.

FLEX CONTAINER
Flex Item
Flex Item
Flex Item
04

Default Flex Direction

Items are arranged in a row by default
flex-row.css
.container {
  display: flex;
  flex-direction: row;
}
1
2
3
4
05

Flex Direction: Column

Arrange items vertically
flex-column.css
.container {
  display: flex;
  flex-direction: column;
}
ITEM 1
ITEM 2
ITEM 3
07

align-items

Control cross-axis alignment

The align-items property controls the alignment of flex items across the cross axis.

align-items.css
.container {
  display: flex;
  align-items: center;
}
ITEM A
ITEM B
ITEM C
08

gap

Add consistent spacing between flex items

The gap property creates consistent spacing between flex items without needing individual margins.

gap.css
.container {
  display: flex;
  gap: 20px;
}
BOX 1
BOX 2
BOX 3
09

Perfect Centering

Center content horizontally and vertically
center.css
.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
PERFECTLY CENTERED
10

flex-wrap

Allow items to move onto multiple lines
flex-wrap.css
.container {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
}
ITEM 1
ITEM 2
ITEM 3
ITEM 4
ITEM 5
ITEM 6
11

Practical Card Layout

A real website Flexbox example
12

Flexbox Quick Reference

Important properties
PropertyPurposeExample
displayCreates flex containerdisplay:flex
flex-directionSets row or columnrow
justify-contentMain-axis alignmentcenter
align-itemsCross-axis alignmentcenter
gapSpacing between items20px
flex-wrapControls wrappingwrap
14

CSS Flexbox Live Example

Run the practical example
LIVE PREVIEW
`;document.getElementById( "sncecFlexPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecFlexRun();} );

HTML Paragraph

  • 17/08/2026

CSS Flex Flow

  • 19/08/2026

CSS Flex Wrap

  • 19/08/2026

Leave a Reply

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