html,body{
width: 100%;
height: 100%;
}
body{
position: relative;
background-color: blue;
}
.box{
background-color: pink;
font-size: 36px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
<html>
<body>
<div class="box">123</div>
</body>
</html>
.outer {
width: 300px;
height: 300px;
background-color: gray;
display: table-cell;
text-align: center;
vertical-align: middle;
}
.inner {
vertical-align: middle;
display: inline-block;
background-color: skyblue;
}
<div class="outer">
<div class="inner">123</div>
</div>
.outer {
width: 300px;
height: 300px;
background-color: gray;
display: flex;
justify-content: center;
align-items:center;
}
.inner {
background-color: skyblue;
}
<div class="outer">
<div class="inner">123</div>
</div>