In this short tutorial we will see how to center div horizontally and vertically in bootstrap 5 .first you need to setup bootstrap 5 project or you can read below article.
How to install & setup bootstrap 5
1. Bootstrap 5 using .d-flex .align-items-center and .justify-content-center class to centered any div element.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bootstrap 5 Div Center</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="d-flex align-items-center justify-content-center vh-100">
<div class="shadow p-4">
<h5>Bootstrap 5 Div Center</h5>
</div>
</div>
</body>
</html>