CSS flex


The CSS flex (short for flexible box) layout is a way to lay out elements on a web page. It allows elements to be positioned in relation to one another and to take up available space in a dynamic and efficient way.

To use the flex layout, you will need to apply the display: flex or display: inline-flex property to the parent element, which will become the flex container. The child elements of the flex container will become flex items.

Here’s an example of how you might use the flex layout to lay out a navigation bar:

    <a href="/">Home</a>
    <a href="/about">About</a>
    <a href="/services">Services</a>
    <a href="/contact">Contact</a>
nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #333;
    color: #fff;
    padding: 10px;

nav a {
    color: #fff;
    text-decoration: none;
    font-size: 16px;
    padding: 10px;

nav a:hover {
    background-color: #444;

This creates a navigation bar with four links that are evenly spaced out and aligned to the center of the container.

There are many other properties that you can use to control the appearance and behavior of flex items and the flex container. Some common ones include flex-direction, flex-wrap, align-items, align-self, and justify-content.