Back CSS

How to center HTML element in CSS

WRITTEN BY ON 15 Dec 2010
8,421 VIEWS • SHARES
0 comments

It's easy to center an element, for firefox and safari, we only need to specify the width and margin left and right set to auto. However, you will need to specify text-align to center in the parent element for IE.

CSS

body {
	text-align:center;	/* for ie	*/
}

#container {
	width:800px;
	margin:0 auto;	
	text-align:left;
}

Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.