Q:

How to Make body to Have 100% of the Browser Height

0

How to Make <body> to Have 100% of the Browser Height

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Set Height for Both <body> and <html> Elements

Simply setting the height of the <body> element to 100% will not have any effect, because percentage (%) height is based on the height of the parent element which is the <html> element. Therefore, we will also have to set the height of the <html> element to 100% to make it work.

Let's try out the following example to understand how it basically works:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Set body Height to 100% of the Browser Window</title>
<style>
    html {
        height: 100%;
    }
    body {
        margin: 0;
        background: yellow;
        min-height: 100%; /* height grows if content grows */
    }
</style>
</head>
<body>
    <div>Some dummy content...</div>
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

HTML / CSS Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Set Space Between Flex Items Using CSS... >>
<< How to Remove Underline from Link in HTML...