[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


how to center a site without using the <center> element (depreciated)?

Posted on 2008-11-07
Medium Priority
Last Modified: 2012-05-05
I would like my site to be centered when requested. So, regardless of the user's monitor size, the site is always in the center.

I tried using the HTML element <center>; it does work; but it breaks some part of the site.

Given the example below, what would you add to the CSS or HTML to display it in the center of the page?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
#container { width: 750px; }
#navigation { width: 100%; height: 1em; float: left; }
#navigation li { display: inline; }
#navigation li a { padding: .25em 1em; float: left;}
#main { width: 500px; float: left; }
#subsection { width: 200px; float: right; }
<div id="container">
<ul id="navigation">
<li><a href="">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Stuff</a></li>
<div id="main">
<p>Duis aute irure dolor ullamco laboris nisi in reprehenderit in voluptate.
Ut labore et dolore magna aliqua. .</p>
<p>Sunt in culpa velit esse cillum dolore qui officia deserunt. Eu fugiat
pariatur. Excepteur sint occaecat lorem ipsum dolor sit amet, sunt in culpa.
Velit esse cillum dolore quis nostrud exercitation duis aute irure dolor.
Ut enim ad minim veniam, excepteur sint occaecat sunt in culpa.</p>
<p>In reprehenderit in voluptate. Quis nostrud exercitation ut labore
et dolore
magna aliqua. Excepteur sint occaecat lorem ipsum dolor sit amet, cupidatat
non proident. Qui officia deserunt quis nostrud exercitation velit esse cillum
dolore. In reprehenderit in voluptate ut aliquip ex ea commodo consequat.</p>
<div id="subsection">
<p>Omnis dolor repellendus. Et quasi architecto beatae vitae consectetur,

Open in new window

Question by:epifanio67

Expert Comment

ID: 22907081
body align="center"
or css body { text-align:center; }
should work

Accepted Solution

kdtresh earned 2000 total points
ID: 22907086
several options using div tags:

LVL 30

Expert Comment

by:Mark Steggles
ID: 22907191

The correct way is to use auto margins like so:

#container {
margin:0px auto;
width: 750px


Author Closing Comment

ID: 31514463
the link gave me the clues.... got the answer... thx

margin: auto


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CSS3 Custom checkboxes This article shows how to style the checkbox form element using only CSS. Works in: Chrome, FF, Safari, Opera, IE9+ Uses modernizr.js to check for :checked pseudo class, falling back to plain old checkboxes (IE8 and bel…
When applying CSS to your HTML, there are many different ways to select which element(s) the CSS applies to.  Some of these selectors are more commonly known and used than others - Here are the more common ones: #X - Matches an ID of X .X - Matche…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question