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;
.