Explore Topics

How Can I Vertically Center a DIV Element in the Body of HTML?

Last Updated : 18 Apr, 2025 - Asked By Ashok

html  center a div 

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



Other Resources

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

Q&A Image
Q&A

Ask your coding-related doubts and get answers.

Certification Image
Certification

Earn certifications to enhance your resume.

internships Image
Internships

Hands-on projects to improve your skills.

Quiz Image
Quiz

Test your knowledge with interactive quizzes.

Interview Questions Image
Interview Questions

Prepare for interviews with curated question sets.

blog Image
Blogs

Add your technical blogs and read technical topics.

Certification Image
Certification

Earn certifications to enhance your resume.

Q&A Image
Q&A

Hands-on projects to improve your skills.

People Also Asked