Center Align HTML Elements

Here are some different way to horizontally center HTML elements:

<div style=”margin: 0 auto; width:500px;  height: 500px;”> some text </div>

The div is centered but the text within it isn’t.

<div style=”margin: 0 auto; text-align: center; width:500px;  height: 500px; “>some text </div>

The div and the text within it are centered.

<div  style=”width:500px;  height: 500px;” align=”center”>some text” </div>

The text is centered but the div isn’t.

<div align=”center”><div  style=”width:500px;  height: 500px;” align=”center”>some text” </div> </div>

The div and the text within it are centered.