Centering with CSS

, ,
Want to master JavaScript in a week? Example based, to the point. Xah JavaScript Tutorial.

This page shows you how to center HTML element using CSS.

Here's a centered element.

I'M IN CENTER

Here's the CSS code:

<div style="
margin-left: auto;
margin-right: auto;
text-align:center;
color:red;
">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