To achieve expected result, use below option of flex items
Below mentioned will center the content vertically and horizontally
align-items: center; // align-items will center content horizontally
justify-content: center;// justify-content will center content vertically
Note: To make justify content vertically center, define html and body full screen height 100%, as by default html,body height is auto which will not cover entire screen
CSS:
html, body{
height:100%;
}
body{
display:flex;
align-items: center;
justify-content: center;
height:100%;
}
Codepen for reference - https://codepen.io/nagasai/pen/JJrPRM