Centering with CSS

Advertise Here

, 2007-03

In old HTML (HTML 3), there's a “center” tag for centering:

<center><p>hi</p></center>

In HTML4 transitional, you can use CSS with align="center".

I'M IN CENTER

Here's the CSS code:

<div style="margin-left: auto;
 margin-right: auto;
 text-align:center;">I'M IN CENTER</div>

In summary, use text-align:center to center a text inside a tag. Use margin-left:auto; margin-right:auto; to center a block level tag.

blog comments powered by Disqus