48

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?

3
  • Could you post some more code? Commented Dec 22, 2013 at 0:19
  • It wouldn't really help the situation in this case. Stephen and matt's answers were sufficient. Commented Dec 22, 2013 at 0:57
  • Ah yeah, they didn't exist when I posted that. Commented Dec 22, 2013 at 2:02

7 Answers 7

59

One option would be to set the left margin to zero:

hr{max-width: 800px; margin-left:0;} 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the concise answer. I gave Stephen the check since his had other info that might be pertinent to future readers.
39

You're trying to use something in a way that (as Eliezer Bernart mentions.. and apparently that comment with the link to the MDN doc disappeared) no longer "works that way". You can, as long as you don't mind it being screwy in IE, just set the margin to zero - http://jsfiddle.net/s52wb/

hr { max-width: 100px; margin: 0px; } 

A better idea though would be to mimic the HR's old way of doing things by way of CSS without the use of the HR. Check out http://jsfiddle.net/p5ax9/1/ for a demo:

p:first-child:before { display: none; } p:before { content: " "; border: 1px solid black; margin-top: 15px; margin-bottom: 15px; display: block; max-width: 100px; } 

2 Comments

The second way is a little too complex for just putting a hr in, for me, but I'll keep it in mind if I use a horizontal line between every paragraph. The first way is perfect though. Thank you.
first option, with only margin-left: 0 worked great, thks
19

I don't know what browsers were used for some above answers, but I found neither text-align:left nor margin-left:0 worked in both IE (11, Standards mode, HTML5) and Firefox (29).

  • IE11: text-align:left works, margin-left:0 leaves rule centred.

  • FF: margin-left:0 works, text-align:left leaves rule centred.

  • So, either use both, or I found that margin-right:100% works for both!

1 Comment

margin-right is the way to go. I found setting it to auto prevented the margin from always extending past the edge of the container.
3

You can use div tag instead.

<div style="border: thin solid lightgray; width: 100px;"></div> 

Comments

1

<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; } 

Comments

0

do this

hr { display: inline; //or inline-block text-align: left; } 

2 Comments

He's mentioned in his question that this didn't work. (Post edited)
This actually made a very short vertical line show up instead. Not sure what that's about. But it definitely doesn't work.
-1

.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" />

1 Comment

I like the idea. But definitely overkill, and all the !important can be very destructive.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.