Styling horizontal rules with CSS is fairly intuitive in IE: to change the color, use the color attribute; to change the width and heights, use the width and height attributes.
Styling horizontal rules in other browsers, however, is slightly less intuitive. To change the color of the horizontal rule, you need to change the background-color attribute. However, this still leaves an unsightly shadow effect that the now-deprecated noshade attribute once took care of. This has led many web authors to stop using the <hr /> tag altogether in XHTML, and fake it with borders on empty divs. But there is a simple solution to this problem – turn off the borders on the <hr>!
hr {border-style: none;}
Dotted-line <hr>s
To go one further and have a dotted-line <hr />, set both the color and background-color to match the color of the element it is contained within. Then add a bottom border with the desired pattern (solid, dotted, dashed, etc) to the <hr />, and viola! A dotted horizontal rule:
hr {color: #fff; background-color: #fff; border: 1px dotted #ff0000; border-style: none none dotted; }
10 comments
Comments feed for this article
Trackback link
February 14, 2007 at 10:22 pm
katie
this was exactly what i was looking for! nice tip!
December 15, 2007 at 5:56 am
moe sett
thanks for your tip
January 17, 2008 at 9:18 am
simon
this is cool – thanks!
i wanted to use these in divs that have various different background colors, so instead of fixing the ‘color’ and ‘background-color’ values I did this:
color:inherit;
background-color:inherit;
which works great (in FF and Opera, that I know of – I don’t have IE or Safari right now).
May 7, 2008 at 7:06 am
Shanti @ Antishay
Thank you!! I have been looking for this :D
September 17, 2008 at 10:14 am
alexander jegulsky
beautiful brief stable resolve!
thanx you lot!
it’s really usefull tip!
April 6, 2009 at 2:07 pm
Chris B
Cheers for the guidance, just what I was trying to find out about.
May 10, 2009 at 10:38 am
Bjorn
You can even set the height to zero: “height: 0″ that way it is transparent if you have a fancy background.
May 19, 2009 at 6:00 pm
Willem
GREAT!! This was what I was looking for!!
May 21, 2009 at 2:44 am
Harry Myint
I have been wondering to do like this.
Very good, thanks.
June 25, 2009 at 2:34 am
jt
Thank you! You are a savior!