Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Guys I'm trying to center this simple ul here. Any idea on whats wrong ?


ul {
    margin-left: auto;
    margin-right: auto;

li {
    display: inline;
    background-color: gray;
    color: white;
    list-style: none;
    margin: 5px;
    padding: 5px;


share|improve this question

closed as off topic by John Conde Dec 10 '10 at 12:57

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

First, I think this question would fit better in doctype or stackoverflow. Also it lacks of more description, perhaps a screenshot... – Dave Dec 10 '10 at 12:11
Correct. HTMLCSS questions belong on Doctype as per the FAQ. – John Conde Dec 10 '10 at 12:58

Because even though the ul centers (with the margin: auto) it's a block element so it spans the entire width of the element. There is no room for margin on either side of it, you'll have to specify a width for the ul element for this to work.

share|improve this answer

Check http://matthewjamestaylor.com/blog/2 it has many HTML/CSS articles.


Again, nothing against being downvoted. But knowing why downvotes (as well as upvotes, unless it is really really obvious) is important indeed to everyone, including me.

Despite the question best fits in other forum (yeah, I commented on question first), I tried a nice reply as per QA seems to be a beginner. And for beginners, I think the best is not just solve the problem, but learn the basics.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.