# CSS Flexbox Layout Guide

* The **CSS Flexbox** layout is used to create flexible and responsive designs. It helps align items easily in rows or columns, making layouts cleaner and more organized. Flex applies only in child element
    
* Flex properties apply only to the child elements of a flex container.
    

**Key Concepts:**

* **Flex Container**: The parent element where Flexbox is applied.
    
* Turns the container into a flexbox.
    
* Default flex direction is row.
    
* The child elements inside the container set in row direction.
    
    ```css
    display: flex;
    ```
    

**Main Concepts**

* **Flex Direction:** controls the direction in which items are placed in the container. **row** is set value in Horizontal layout. **column** is set value in vertical layout.
    
    ```css
    flex-direction: row;
    ```
    
* **Justify Content:** Aligns items along the main axis (horizontal by default).
    
    ```css
    justify-content: center; 
    ```
    
* **Align-items:** aligns items along the cross axis (vertical by default).
    
    ```css
    align-items: center; /* Center items vertically */
    ```
    
* **Flex-wrap:** allows items to wrap onto the next line if they don’t fit in one row/column.
    
    ```css
    flex-wrap: wrap; 
    ```
    
* **Align-Content:** Aligns multiple rows along the cross axis. but it’s only work when flex-wrap is used.
    
    * `flex-start`, `flex-end`, `center`, `space-between`, `space-around`, `stretch`.
        
    
    ```css
    align-content: space-between; /* Space rows evenly */
    ```
    

---

### **How Flex Work?**

* Flex work on cross axis and main axis. **align-items** property work on **cross axis** and **justify-content** property works on **main-axis.**
    
* You can easily understand using this diagram.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1737660929949/31d54de5-cd17-44c2-a2bc-d18c37a05032.png align="center")

* Understanding the **main axis** and **cross axis** is crucial for controlling how items are laid out and aligned in a flex container. With these axes, you can precisely manage the positioning of items in any layout!
    

---

### Flexbox Cheat Sheet

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1737661090154/575da76a-2371-475d-b700-df76134d5d14.png align="center")

---

## **Conclusion**

If you found this article helpful, Like and share it with others and feel free to leave your feedback—I’d love to hear your thoughts!

I write articles on [renilpatel.hashnode.dev](https://renilpatel.hashnode.dev) and also post development related content on the following platforms:

* **Twitter** - [Link](https://x.com/renilgarala)
    
* **LinkedIn** - [Link](https://www.linkedin.com/in/renilgarala/)
