Call me stupid, but i’ve always been told that you can’t center the contents of an unordered list as used in the footer menu for many websites (maybe that goes to show that many people don’t know what they’re on about?) the solution just popped into my head – try it for your self!

styles:

#footer{text-align:center;list-style:none}
#footer li{display:inline}

HTML

<ul id=”footer”>
<li><a href=”1.asp”>Link 1</a></li>
<li><a href=”2n.asp”>Link 2</a></li>
<li><a href=”3.asp”>Link 3</a></li>
</ul>

Simple stuff indeed!

Written by Mark Rushworth

Mark Rushworth

With over 14 years experience in online design and marketing I, like many others, began my professional life as a web designer before realising my talent for digital marketing. This I have pursued as my primary career focus since 2007. Since then Ive worked across all sectors for clients big and small delivering the best bang for your buck.

Related Posts:

  • No Related Posts

Discussion

  1. evsap

    Thank you. I was just wondering the same thing and was looking for the solution.

  2. mary

    how would you center the unordered list if the lis were set to display: block (in case i want to have backgrounds on them or set a height)?

    • Mark Rushworth

      Hi Mary, try display:inline-block where you can set the width and height (not in ie6 tho i think) or you could nest the li making the first li 100% wide.

  3. Juan

    I was looking so much for the solution… very simple and works perfect!
    Congrats, thanx!

  4. Rahul Bansal

    Hi Mark,

    It worked like charm! :-)
    Thanks for saving my day

    -Rahul

  5. Daniel

    Thanks, very helpful! I wasn’t sure it could be centered that easily, I’m glad I googled it before creating nested divs and other gnarly stuff like that :)

  6. Brian H.

    I’m trying to do the opposite, I don’t want my list centered. I have it on my footer at http://anytimeteas.com

    Here’s my css (warning, I don’t really know what I’m doing). I’d like the lists flush to the left and the headers to each column in the same location, preferably on the left side, directly above each list.

    .footer-item {
    float: left;
    width: 33%;
    padding-bottom: 10px;
    }
    .footer-item ul {
    padding-left: 15px;
    }

  7. Luis C.

    Hi Brian,

    Nice article, it helped me out today :)

    Try to add text-align: left to the footer-item class. it might look almost like you want.

  8. Orlando

    thanks a lot =) simple solution for an annoying problem..

  9. Razu Kc

    AWESOME!

    Thank you so much!

    I was trying differently and the solution was so simple.

  10. scorpy

    simple though, but just what i needed! thanks!

  11. Andy Bramwell

    @brian H

    set your width to 100% and your button will be at the left hand side

    Andy :D

  12. Dina Barbosa

    You are a saint! Just saved my day :)
    Thank You!

  13. Dave Sellers

    Superb, just what I was looking for. Nicely done!

  14. Kenny

    Thanks, that works like a charm.

  15. David Selkirk

    Thanks! I was messing with this for quite a long time on a few different projects. I don’t know why I never searched for a solution. great work.

  16. Ryan

    Thanks.
    This problem was too simple, so I was looking for an overly complex solution.

  17. Brad

    Man, I wish I had found this post earlier. Wasted close to an hour messing with margins. Thanks for posting the tip.

  18. Andy Townsend

    Thanks Mark. A simple solution and just what I needed.

  19. Connor

    I spent about 30 mins trying to figure this out with loads of unnecessary code before I decided to Google and found this. Thank you so much, so simple and so elegant.

  20. Naji

    But how about if it was a vertical list and I want to horizontally center each list item within the ul?
    I tried {margin: 0 auto} but as was stated on CSS-tricks, that won’t work. And, I couldn’t really use his solution since he’s doing a horizontal list. Any advice? Thanks.

  21. Chris

    Hey. Thought to myself this must be way simpler than the current solution I have. Thanks.

  22. Sam Orchard

    You can do almost anything with CSS, including over-writing an element’s default styling properties. A worthwhile lesson though – a lot of people don’t know what they’re on about :P

  23. Bas

    and if you want the align the ul to the bottom of the surrounding div?

  24. cyberprodigy

    .myUL {
    display:block;
    text-align:center;
    }
    .myUL li {
    display:inline-block;
    }

  25. ahmad balavipour

    Thanks alot,

    before this i am using li{ float:right;} for foot menu, thanks for solution

  26. Dwayne

    Just what I needed. Thanks for posting!

  27. vishu

    thanks a lot

  28. Chris

    Thanks for the tip, I see this isn’t a new article, but is still serving the public. Cheers!

  29. Tom

    Great Job Mark, I’ve been trying to figure this out for days!

  30. Michael Berlin

    Thank you, I was stuck with that simple little thingy for 30 minutes now…

  31. Jonathan Sabo

    You need to add

    #footer {padding-left:0;}