Centering with CSS

By Xah Lee. Date: . Last updated: .

To center a block level element, use:

margin-left: auto;
margin-right: auto;

Here's a centered element.

wow

Here's the code:

.cen49653 {
margin-left: auto;
margin-right: auto;
}
<div class="cen49653">wow</div>
JS in Depth
XAH  BUY NOW

CSS

Basics

Color

Font

Text Decoration

Box Model

Box Decoration

Layout

Layers

Transform/Animation

Line Wrap

Misc