Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • CSS Tutorial
  • CSS Exercises
  • CSS Interview Questions
  • CSS Selectors
  • CSS Properties
  • CSS Functions
  • CSS Examples
  • CSS Cheat Sheet
  • CSS Templates
  • CSS Frameworks
  • Bootstrap
  • Tailwind
  • CSS Formatter
Open In App
Next Article:
Advance CSS Layout with Flexbox
Next article icon

Explain the concept of the CSS Flexbox

Last Updated : 01 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The CSS Flexbox (Flexible Box) model is a layout mechanism that provides a straightforward and efficient way to design complex, responsive, and dynamic web layouts. Introduced to address challenges posed by traditional layout models, Flexbox simplifies the alignment and distribution of space among items within a container, regardless of their size or order.

Table of Content

  • Container and Items
  • Flex Direction
  • Justify Content
  • Align Items and Align Self
  • Flex Wrap
  • Flex Grow, Shrink, and Basis

Container and Items

Element TypeDescription
Flex ContainerThe parent element that contains a group of flex items is known as the flex container. Apply display: flex or display: inline-flex to transform an element into a flex container.
Flex ItemsThese are the children of the flex container. These items automatically become flexible boxes, allowing them to adjust to different screen sizes.

Flex Direction

Defines the primary axis of the flex container, determining the direction in which flex items are placed. Options include row, column, row-reverse, and column-reverse.

Justify Content

Specifies how flex items are distributed along the main axis. Options include flex-start, flex-end, center, space-between, and space-around.

Align Items and Align Self

CSS PropertyDescription
align-itemsAligns flex items along the cross-axis of the flex container. Options include flex-start, flex-end, center, stretch, and baseline.
align-selfOverrides the default alignment for a specific flex item within the container. Options match align-items values: flex-start, flex-end, center, stretch, and baseline.

Flex Wrap

Determines whether flex items should wrap into multiple lines if they exceed the container's dimensions. Options include nowrap, wrap, and wrap-reverse.

Flex Grow, Shrink, and Basis

CSS PropertyDescription
flex-growDefines the ability of a flex item to grow and fill the available space in the flex container. A higher value indicates a greater ability to grow.
flex-shrinkDetermines the ability of a flex item to shrink if there's not enough space in the flex container. A higher value indicates a greater ability to shrink.
flex-basisSpecifies the initial size of a flex item before any remaining space is distributed. It sets the starting size of the item in the main axis.

Benefits of Flexbox:

  • Responsive Design: Simplifies the creation of responsive layouts that adapt to various screen sizes.
  • Easy Alignment: Facilitates effortless alignment of items both horizontally and vertically.
  • Ordering: Allows reordering of flex items without altering the HTML structure, enhancing flexibility in layout design.
  • Dynamic Sizing: Enables dynamic adjustment of item sizes based on available space.

Next Article
Advance CSS Layout with Flexbox

P

pankaj_gupta_gfg
Improve
Article Tags :
  • Web Technologies
  • CSS
  • CSS-QnA
  • WebTech-FAQs

Similar Reads

  • Explain the purpose of clearing floats in CSS
    In this article, we will learn to clear float and the purpose of clearing floats in CSS. Before diving into this topic, we will know the float property in CSS. The float property in CSS is used to change the normal flow of an element. The float property defines where should be an element place conta
    2 min read
  • Primer CSS Flexbox Example Components
    Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by
    3 min read
  • Advance CSS Layout with Flexbox
    Flexbox is a powerful CSS layout model that simplifies the creation of flexible and responsive layouts. It allows you to align and distribute space among items within a container, making complex designs easier to manage. Flexbox is particularly useful for building responsive designs that adapt seaml
    5 min read
  • Explain the working of the Block Formatting Context
    What is Block Formatting Context (BFC)? Block Formatting Context is a layout concept used in CSS to determine the position and size of elements on a webpage. It is used to control the layout of elements on a webpage, such as positioning elements in a specific location and controlling the size of ele
    4 min read
  • Explain the term “pseudo-class” in CSS3
    Cascading Style Sheets referred to as CSS is a stylesheet language used to design and describe the presentation of the webpage to make it attractive. The main use of CSS is to simplify the process of making web pages presentable. The way elements should be rendered on screen is described by CSS. CSS
    4 min read
  • How to Display Three Columns Per Row in CSS Flexbox?
    CSS Flexbox is a one-dimensional layout model that allows items within a container to be arranged in rows or columns with dynamic sizing and alignment. It simplifies the process of creating complex layouts and responsive designs. In this article we will explore approach to arrange columns in a conta
    2 min read
  • Complete Guide to CSS Flexbox
    Flexbox, short for Flexible Box Layout, is a one-dimensional layout method for aligning and distributing space among items in a container. It allows you to design layouts that adapt to different screen sizes, making it ideal for responsive web design. Flex Container: The parent element that holds fl
    8 min read
  • Primer CSS Flexbox Flex Container
    Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Primer CSS Flexbox Flex Container is
    2 min read
  • Primer CSS Flexbox Justify Content
    Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Primer CSS Flexbox Justify Content cl
    4 min read
  • How to Set a Fixed Width Column with CSS Flexbox ?
    When working with CSS flexbox, setting a fixed width for a column can be achieved by using various approaches to override the default behavior of flex items, which typically grow and shrink to fill available space. Table of Content Using the flex propertyUsing the min-width and max-width propertiesC
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences