HTML height
Created By: chatGPT
To set the height of an HTML element, you can use CSS. The height
property defines the vertical size of an element. Here’s a quick example of how to set the height of a <div>
using CSS:
css .box { height: 200px; background-color: lightblue; }
This would create a <div>
that is 200 pixels tall. You can also use percentages if you want the height to be relative to its parent element:
css .parent { height: 500px; }
.child { height: 50%; / This will be 250px if parent is 500px / background-color: lightgreen; }
If you want the element height to adjust based on the viewport, use the vh
(viewport height) unit:
css .responsive { height: 50vh; / This will be 50% of the viewport height / }
<div class="box"></div>
<div class="parent">
<div class="child"></div>
</div>
<div class="responsive"></div>