Centering an <hr> tag

Phil picture Phil · Jul 15, 2014 · Viewed 23.9k times · Source

I'm having some trouble with my hr tag in HTML, as it isn't automatically centering as I expect it to. This is what my current code looks like:

<div id = "updatestatus" class = "statuscontainer">
    <div class = "verticalalign">Update Status</div>
</div>
<hr width = "95%">

<div id = "insertstatus" class = "statuscontainer">
    <form></form>
</div>

As you can see, I'm placing my hr tag in between two divs, and I believe it's supposed to automatically center, but it ends up going to the left instead. I have also tried hr align = center with no success either.

Edit: I just realized that when I place the entire hr tag within <center></center> it centers, but I'm still trying to figure out why it doesn't center on its own.

Answer

Gaurav Singh picture Gaurav Singh · Aug 23, 2019

Try margin: auto;

<hr style="width:100px; margin: auto;" />