Centre anything with Flexbox
The shortest way to centre content both ways.
CSS · Centre anything with FlexboxBeginner
.center {
display: flex;
justify-content: center; /* horizontal */
align-items: center; /* vertical */
min-height: 100vh;
}
/* Even shorter, with Grid */
.center-grid { display: grid; place-items: center; min-height: 100vh; }flexboxcenterlayout