Two right ways to center a div in CSS in 2023

--

Two right ways to center a div in CSS in 2023

When you google this question, you will find a lot of ways to do it. 😍

But… It will be out of date. πŸ˜’

In 2023, we have only 2 right ways to do it:

1. Flex

  .parent {
display: flex;
justify-content: center;
align-items: center;
}

2. Grid

  .parent {
display: grid;
place-items: center;
}

Happy hacking! ✌🏻😊

--

--