Replacement for <center>

Viewed 30689

This has been asked before by other people, but I've never seen an adequate answer. Is there a valid replacement to the <center> tag?

I know there's margin: 0 auto;, but that requires setting a width. There's also align="center", but I believe that that's invalid code as well.

Is there something as simple as <center> that's valid? There are rare occasions where I still end up using it, even though it is deprecated. Just today, I ended up using a <center> to center the one button that needed centered on a web page. Yes, I could have set the width and gave it margin: 0 auto, but that's a lot of work for centering one single element, and it dirties up my code, which I take pride in keeping orderly. I don't really understand why <center> was deprecated in the first place, if nothing has replaced it.

Thanks!

9 Answers

Replacement for center tag: (You should do both)

Use this style for parent element:

text-align:center;

Use this style for current element:

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

Related