Open In App

How to make Flexbox Children 100% Height of their Parent using CSS?

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Flexbox is an incredibly powerful layout model in CSS, enabling developers to create responsive designs with ease. It's especially effective—used in over 85% of modern websites—for distributing space evenly among child elements and aligning them efficiently. One common use case is when you want child elements to take up the full height (100%) of their parent container, ensuring a consistent and balanced layout regardless of screen size 1. Using Flexbox and the Height Property

We can use the display: flex property to create a flexbox child and use the height: 100% property to make the flex height 100% of the container. This method ensures that the child flexbox takes the full height of the parent container.

index.html
<!DOCTYPE html>
<html>
<head>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        .container {
            width: 100vw;
            height: 20vh;
            background-color: green;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        .child-div {
            height: 100%;
            background-color: red;
            margin: 0 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="child-div">
            One
        </div>
        <div class="child-div">
            Two
        </div>
        <div class="child-div">
            Three
        </div>
        <div class="child-div">
            Four
        </div>
        <div class="child-div">
            Five
        </div>
    </div>
</body>
</html>

Output

output

2. Using align-item Property

The align-items: stretch; approach ensures that flexbox children automatically stretch vertically to fill the entire height of their parent container, eliminating the need for explicit height declarations on the children.

index.html
<!DOCTYPE html>
<html>
<head>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        .container {
            width: 100vw;
            background-color: green;
            display: flex;
            justify-content: center;
            align-items: stretch;
            height: 30vh;
        }
        .child-div {
            background-color: red;
            margin: 0 20px;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="child-div">
            One
        </div>
        <div class="child-div">
            Two
        </div>
        <div class="child-div">
            Three
        </div>
        <div class="child-div">
            Four
        </div>
        <div class="child-div">
            Five
        </div>
    </div>
</body>
</html>

Output

output

Note: CSS is the foundation of webpages and is used for webpage development by styling websites and web apps. You can learn CSS from the ground up by following this CSS Tutorial and CSS Examples.


Similar Reads