DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Center HTML Content Horizontally Using CSS

12.20.2006
| 23869 views |
  • submit to reddit
        Ahh the infamous CSS centering thing... make sure to specify the width and set the right/left margins to 'auto'

#content {
        margin: 0 auto;
        width: 740px;
}

Your HTML would look something like this:
<div id="content">
        This is centered
</div>