How to set percentage height with HTML and CSS?

Spread the love

Sometimes, we want to set percentage height with HTML and CSS.

In this article, we’ll look at how to set percentage height with HTML and CSS.

How to set percentage height with HTML and CSS?

To set percentage height with HTML and CSS, we set the percentage height on all ancestor elements.

For instance, we write

html,
body {
  height: 100%;
  margin: 0;
}

div {
  height: 100%;
  width: 100%;
  background: red;
}

to set the height of the html, body, and div elements so that the heights of all the elements can be set as percentages.

Conclusion

To set percentage height with HTML and CSS, we set the percentage height on all ancestor elements.

Leave a Reply

Your email address will not be published.