How to center ul and li in a div with CSS?

Spread the love

To center ul and li in a div with CSS, we use flexbox.

For instance, we write

ul {
  justify-content: center;
  display: flex;
}

to make the ul a flex container with display: flex;.

And we center the contents horizontally with justify-content: center;.

Leave a Reply

Your email address will not be published. Required fields are marked *