CSS – Set Height for Div

To set a specific height for Div element using CSS, set height property with required value for the selected Div elements in styles(inline/external).

Example

In the following HTML script, we have set height property for Div elements with different values.

index.html

</>
Copy
<!DOCTYPE html>
<html lang="en">
    <head>
        <style>
            div {
                background-color: green;
                width: 200px;
                margin: 10px 0;
            }
            #div1 {
                height: 50px;
            }
            #div2 {
                height: 150px;
            }
            #div3 {
                height: 250px;
            }
        </style>
    </head>
    <body>
        <div>Div</div>
        <div id="div1">Div 1</div>
        <div id="div2">Div 2</div>
        <div id="div3">Div 3</div>
    </body>
</html>

Conclusion

In this CSS Tutorial, we learned how to set height value for Div element(s) using CSS.