Rijk
Rijk

Reputation: 1

How to align a div in the center of a HTML page?

I've to align some text in the center of the page with div tag.

Upvotes: 0

Views: 398

Answers (4)

Touhid Rahman
Touhid Rahman

Reputation: 2583

Simply use the following styling:

div {margin:0 auto;}

Upvotes: 0

Laserson
Laserson

Reputation: 533

You can try <div align="center">...</div>

Upvotes: 0

kafuchau
kafuchau

Reputation: 5593

You could set the style of the div to be:

<div style="width: 250px; margin-left:auto; margin-right:auto;">TEXT</div>

You can also place that style in a CSS class and set the class of the div to whatever you named it.

EDIT: If you include a width for the div, it centers...

Upvotes: 0

meder omuraliev
meder omuraliev

Reputation: 186552

div#foo { text-align:center; }

to align the text within the div or

div#foo { width:100px; margin:0 auto; }

to make the div 100px width and horizontally center it.

Upvotes: 5

Related Questions