Real Dotted-line <hr>s

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


  1. katie’s avatar

    this was exactly what i was looking for! nice tip!

    Reply

  2. moe sett’s avatar

    thanks for your tip

    Reply

  3. simon’s avatar

    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).

    Reply

  4. Shanti @ Antishay’s avatar

    Thank you!! I have been looking for this :D

    Reply

  5. alexander jegulsky’s avatar

    beautiful brief stable resolve!
    thanx you lot!
    it’s really usefull tip!

    Reply

  6. Chris B’s avatar

    Cheers for the guidance, just what I was trying to find out about.

    Reply

  7. Bjorn’s avatar

    You can even set the height to zero: “height: 0″ that way it is transparent if you have a fancy background.

    Reply

  8. Willem’s avatar

    GREAT!! This was what I was looking for!!

    Reply

  9. Harry Myint’s avatar

    I have been wondering to do like this.

    Very good, thanks.

    Reply

  10. jt’s avatar

    Thank you! You are a savior!

    Reply

  11. Beej’s avatar

    Brilliant, thanks very much for the tip

    Reply

  12. Dwayne’s avatar

    You just saved my life. I was banging my head against my monitor pretty hard and your solution probably saved my ass, thanks for posting this.

    Reply

  13. KP’s avatar

    Thanks for making this post. I was forced to use an HR, and this made it less painful to do so.

    Reply

  14. Pajari’s avatar

    Thanks a lot!

    A tip: you can also utilize “inherit”, as in the following:

    hr {
    color:inherit;
    background-color:inherit;
    border:1px dotted #2B2B2B;
    border-style:none none dotted;
    }

    Reply

Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>