Waiting Answer November 04, 2023

How can I vertically center a div element in the body of HTML?

Answers
2023-11-09 06:17:59

To vertically center a `div` in the body of HTML, you can use either Flexbox or CSS Grid:

*Flexbox:*
css
body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
}


*CSS Grid:*
css
body {
    display: grid;
    place-items: center;
    height: 100vh;
    margin: 0;
}

Your Answer