Align <hr> to the left in an HTML5-compliant way

Viewed 86637

Currently, I'm using

<hr align="left" />

on my HTML5 page, but I've read that the align property was deprecated in XHTML 4.01 and supposedly removed from HTML5. I'd like to be using CSS rather than an inline attribute like this, but when I tried

hr{align: left; max-width: 800px;}

or hr{text-align: left;} or hr{left: 0;} or hr{float: left;}, it just showed up in the center.

So what should I use instead of the inline attribute above?

7 Answers

<hr> tags have margin-inline-start and margin-inline-end properties set to auto, which centers the element horizontally (similar to setting both left and right margins of an element to auto).

To left-align an hr tag, you can set margin-inline-start to 0:

hr {
    margin-inline-start: 0;
}

...and you can right-align an hr tag by setting margin-inline-end to 0:

hr {
    margin-inline-end: 0;
}

.line {
    height: 2px;
    background-color: var(--itemBorder);
    color: var(--itemBorder);
}
.width100 {
    width: 100% !important;
}
.width90 {
    width: 90% !important;
}
.width80 {
    width: 80% !important;
}
.width70 {
    width: 70% !important;
}
.width60 {
    width: 60% !important;
}
.width50 {
    width: 50% !important;
}
.width40 {
    width: 40% !important;
}
.width30 {
    width: 30% !important;
}
.width20 {
    width: 20% !important;
}
.width10 {
    width: 10% !important;
}
<div class="line width100" />

Related