Centering with CSS

By Xah Lee. Date: . Last updated: .

To center a block level element, use:

Here's a centered element.

I'M IN CENTER

Here's the code:

<div style="
margin-left: auto;
margin-right: auto;
text-align:center;
color:red;
">I'M IN CENTER</div>
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS Basics
  4. JS in Depth
  5. JS Reference
  6. DOM
  7. SVG
  8. JS Misc