Centering a div with css

Originally written: 2020 August 26

Sometimes you just need to center a div for some reasons. Here's how.

.centered-div {
    /* Place div in center of screen */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    /* Place text in center of div */
    display: flex;
    text-align: center;
    align-items: center;
    justify-content: center;

Hope this helps!