Style HR Horizontal Rule with CSS

May2710May 27, 10

Update: (May 27th, 2010) Corrected IE issue, removed outdated Opera and Safari workarounds.

It's a tricky subject, the <hr /> element. Like the <br /> element, it's syntactically odd and browsers have specific default styles for it that vary quite a bit. Since the goal is always to keep our HTML uncluttered, I thought I would explain how to work with this unruly piece of a document.

First, the HTML for this tutorial is always the following:
<hr />

 - That's how the HTML specifications say we are to indicate a horizontal line, so that's all we want to use in the content layer. Presentation, on the other hand, will be a little more messy and unusual. First, let's remember the major browser quirks associated with the HR element, many of them from this article:
Internet Explorer allows color to define the background color, and gives it precedence over background-color
The border property does not behave correctly in Opera
The height property is (by default) broken in Safari
With these rendering issues in mind, the goal is to make our HR elements look like they have been cut into the page - a common visual effect used most notably by Apple:

Not that we should do everything Apple does, but they can whip up a mean UI.

To avoid this going on forever, here are the two bug fixes that need to be used to get things working across the major browsers:

The workarounds below are no longer needed by Opera and Safari:
Fixing the height property in Safari:
This one is simple, but not intuitive. For whatever reason, the height property is limited to a minimum of 3px in Safari. The easiest way to get around this is to set the max-height property to whatever the height of your HR needs to be. In our case, we're only using borders to style the element, so the max-height should be 0.
height: 0;
max-height: 0;

Fixing Opera's borders:
It looks like Opera renders the border-top and border-bottom properties correctly. That's a bonus, because those are the only ones we need. You might have noticed, though, that Opera has the same problem as Safari when setting the height of a horizontal rule element. Thankfully, the fix is also the same.

Making Internet Explorer 6 Behave:
First, we're not using the color or background-color properties, so that eliminates those IE bugs. Second, I don't test on IE6 because that browser only accounts for about 2% of the visitors to most of my sites. But, everyone should at least be able to view the un-styled HTML properly. The beauty of using only a single HR element to show horizontal lines is that the degradation is already built into every browser.

However, it's always a good idea to predict when IE6 can be made to work with little extra effort. Typically, the problems people run into are with minimum heights due to the font-size property having precedence, and floats not breaking properly. To avoid these potential annoyances, I decided to include a few lines:

font-size: 1px;
line-height: 0;
overflow: visible;

The rest is the same as you would have used if styling an empty div element instead of an hr element:

display: block;
position: relative;
padding: 0;
margin: 8px auto;
width: 100%;
clear: both;
border: none;
border-top: 1px solid #AAA;
border-bottom: 1px solid #FFF;
font-size: 1px;
line-height: 0;
overflow: visible;

Now we've got a working horizontal rule, styled properly using only CSS. 
It looks like this:

And in Internet Explorer 5.5, we have the exact same style applied:

Beautiful, sleek, and it looks identical across all the browsers people use.

About Jason Miller:

I am a JavaScript developer from Waterloo, Ontario, Canada. When I am not typing green code onto a black screen, you might find me at the nearest coffee pub checking out the brew. I run a internet firm called developIT and maintain blogs and web apps when I can.
Not working in IE6 :) (test this page in IE6)
What does it look like in IE6? I no longer test in that browser (I can't find a Windows install old enough and got sick of running VMs while Photoshop was open)

I don't care about IE6 as long as the fallback is some kind of horizontal bar. If it's completely disappeared, then something nasty with the star hack might be in order.
"presidence" ??
@ohreally: Good catch, I must have had Spell Check disabled when I wrote this.
Yep, works great, though I had to remove 'clear: both' to get them all spaced correctly (using more than one on a page). First one was incorrectly spaced above the line, before I removed this, the rest were fine.
Drew Geraets#
You should also add height: 0; - otherwise you end up with a pixel space between the borders in Chrome and Safari.
@drew: On what platform? I'm not seeing any space in Chrome or Safari under Windows or OS X...
I'm seeing a huge gap in between paragraphs in Google Chrome. How can I fix this to make it look like the one I see in Internet Explorer 9?
@lisa: that would seem to be your paragraph styling, which differs wildly between browsers. Try this:

p {
padding :0;
margin: 0.5em 0;
Hi Jason. HTML5 spec for the hr tag is simply <hr>, and not <hr />. Your post is showing the spec for XHTML, and not current HTML spec. Hope that helps!
Hi Jason. HTML5 spec for the hr tag is simply <hr>, and not <hr />. Your post is showing the spec for XHTML, and not current HTML spec. Hope that helps!
@Drew: This post was written before HTML5 was a thing! I used to love the idea of XHTML, likely because I am bad at writing parsers. Perhaps I will correct the self-closing tag if I ever start writing content for this site again ;)
jlgg# nike shoes australia mk bags coach online ray ban prescription sunglasses moncler jacket michael kors purses on sale adidas yeezy boost 350 burberry online bercrombie Nederland michael kors Oakley Outlet Ralph Lauren Polo oakley sunglasses KD 8 shoes coach factory oakley australia major league baseball baseball jerseys Nike Free pandora rings burberry outlet ray ban sunglasses prada bags outlet michael kors abercrombie paris canada goose outlet Jordan Retro prada outlet nike australia pandora charms yeezy boost 350 burberry outlet beats by dre yeezy boost 350 Ralph Lauren UK moncler coats Hermes Outlet piumini moncler replica Abercrombie Fitch tiffany co moncler clothing moncler jacket mens kate spade outlet paul smith uk michael kors outlet coach outlet prada bags Ray Ban Outlet michael kors outlet kate spade outlet michael kors italy kate spade bags landing gears china factory sale Canada Goose Outlet canada goose sale online Yeezy 350 michael kors outlet ray ban sunglasses kate spade canada moncler sale coach purse prada purses prada factory outlet online authentic prada handbags outlet Adidas Yeezy Boost 350 michael kors bags Cheap Ray Ban ugg australia nike jordan polo outlet prada handbags coach outlet nike shox shoes Jordan Retro Shoes coach carter pandora charms sale clearance Kevin Durant Shoes coach outlet ray ban sunglasses coach purses michael kors uk prada handbags Nike Hyperdunk 2015 moncler outlet michael kors handbags outlet B Derbyshire nike id ray ban aviator kate spade black friday burberry purse Michael Kors Outlet michael kors jet set tote prada factory outlet online louis vuitton outlet prada outlet online Longchamp Outlet kate spade bags nike basketball shoes ray ban glasses kate spade outlet pandora charms sale moncler outlet prada outlet clk benz burberry outlet canada nike shoes coach bags abercrombie us moncler uk ray-ban sunglasses Nike KD 8 coach usa adidas shoes abercrombie outlet prada outlet prices michael kors canada veronique Billat michael kors outlet michael kors tote abercrombie fitch coach outlet nike lebron shoes wholesale pandora rings burberry outlet online Kobe X Shoes pandora rings ray ban prescription glasses Nike Kobe 9 pandora charms Burberry outlet online coach outlet nike jordan shoes sunglasses hut michael kors outlet bags michael kors online burberry scarfs coach outlet ugg australia true religion uk burberry us kate spade outlet coach australia michael kors australia nike outlet huarache nike ray ban clubmaster tiffany co pandora bracelets burberry australia kate spade purses outlet official michael kors pandora rings nike jordan shoes air jordan shoes air jordan shoes ups tracking coach outlet nike free run abercrombie and fitch mcm factory outlet prada outlet online nike com burberry outlet online pandora bracelet adidas australia Pandora bracelet longchamp outlet nike australia burberry online ralph lauren australia Ralph Lauren Hugo Boss Store kate spade black friday abercrombie & fitch asics Australia cheap coach purse michael kors bags outlet pandora charms uk air jordan retro burberry canada true religion uk pandora ring authentic prada outlet online coach handbags coach sunglasses for women nfl jerseys Chanel bags Outlet louis vuitton outlet coach outlet online michael kors outlet oakley sunglasses burberry canada authentic prada outlet online pandora rings mk outlet pandora princess ring hermes bag michael kors handbags prada outlet online longchamp outlet abercrombie outlet kate spade outlet michael kors michael kors us rayban aviator coach factory outlet online ralph lauren uk prada outlet online ray ban online cheap ray ban sunglasses nike air max coach outlet online nfl shop pandora rings sale lebron james shoes ugg uk louis vuitton factory outlet coach outlet coach outlet mlb shop ugg boots michael kors outlet michael kors outlet prada bags ray ban wayfarer ralph lauren uk prada outlet online Oakley Holbrook prada handbags cheap moncler jacket Coach Sunglasses Outlet burberry scarf michael kors outlet online oakley sunglasses basketball jerseys nike lebron james ray ban outlet prada outlet online pandora rings nike store kate spade pandora necklace charms ray ban eyeglasses burberry outlet Nike Air Max pandora bracelet jordan shoes beats headphones pandora rings michael kors outlet abercrombie outlet prada outlet kate spade canada goose sale pandora charms prada outlet prada bags on sale huaraches ray-ban sunglasses nike huarache shoes michael kors outlet kate spade outlet online pandora rings coach bag Nike Air Jordan pandora uk chanel coach outlet michael kors purses michael kors outlet hermes uk yeezy boost 350 shoes ray-ban sunglasses Pandora Charm canada goose jacket Mizuno Wave coach handbags coach factory outlet burberry burberry australia abercrombie and fitch michael kors purses outlet pandora jewelry baseball jerseys louboutin shoes ray ban new wayfarer mk handbags prada outlet online Mizuno Running Shoes coach australia yeezy boost 350 paul smith sale Chanel Outlet CHanel Factory Outlet jordan retro shoes burberry outlet louis vuitton outlet Hyperdunk 2016 pandora charms coach factory outlet Official Ralph Lauren UK Online Store coach outlet store coach outlet landinggear Kate Spade Australia Billat kate spade outlet oakley frogskins sunglasses asics shoes sunglasses hut Coach Outlet Online Ralph Lauren Polo snow boots Mizuno Shop Japan Hugo Boss Online prada bags Kobe 9 Shoes shoes online kate spade bags outlet prada outlet ray ban outlet louis vuitton outlet prada bag pandora charms coach coach australia michael kors outlet burberry scarf coach factory outlet pandora jewelry prada sunglasses timberland boots nike outlet salomon hiking shoes pandora australia michael kors outlet Prada Outlet oakley frogskins michael kors outlet kate spade adidas australia nike jordan shoes burberry outlet Polo Ralph Lauren pandora necklace coach outlet burberry scarf canada goose jacket coach outlet online football jerseys pandora australia hockey jerseys shoes sale paul smith prada outlet online mcm outlet michael kors outlet michael kors black friday mlb shop cheap basketball shoes Mizuno Shop louis vuitton outlet ralph lauren pandora australia Polo Ralph Lauren michael kors tote pandora uk Mizuno Shoes louis vuitton australia michael kors wallet coach outlet coach shoes pandora charms sale online Nike Jordans Prada Factory Outlet jimmy choo australia michael kors outlet online ray ban sunglasses ray ban polarized michael kors outlet prada factory outlet online michael kors factory outlet burberry outlet veronique billat moncler us chanel australia coach outlet polo online huaraches shoes beats studio asics shoes Australia moncler mens jackets pandora necklaces ralph lauren shirts basketball jerseys polo outlet online Bed and Breakfast in chesterfield michael kors bags flash sunglasses shoes online sale salomon shoes abercrombie and fitch Coach outlet online coach outlet abercrombie outlet us Hugo Boss Outlet oakley outlet pandora australia michael kors outlet coach diaper bag baseball jerseys michael kors outlet true religion jeans michael kors handbags abercrombie outlet ugg slippers burberry outlet canada michael kors outlet moncler down jackets nike air huarache pandora rings jewelry kate spade outlet michael kors bags michael kors outlet nike huarache prada official site moncler jacket michael kors outlet Oakley Holbrook sunglasses timberland uk china wholesale coach factory top sunglasses Nike Air Jordan kate spade handbags Jordan retro Michael Kors Outlet kate spade outlet online coach outlet online michael kors outlet official prada site Free Run kate spade purses nike shox michael kors outlet prada outlet Whitton Lodge Chesterfield Derbyshire UK Basketball shoes abercrombie outlet michael kors kate spade handbags Nike Hyperdunk Shoes michael kors uk abercrombie us mcm outlet online pandora jewelry nike shoes michael kors outlet mens sunglasses Nike Jordan Shoes coach factory outlet ralph lauren Michael Kors Canada sunglasses sm pandora charms black friday pandora charms sale football jerseys pandora charms michael kors outlet sunglasses outlet prada us prada bags mlb store coach sunglasses prada factory outlet prada online louis vuitton uk michael kors handbags moncler outlet landing gear official prada site coach bags pandora bracelet chanel bag michael kors totes Coach Outlet Store moncler jacket brand sunglasses michael kors outlet Yeezy Boost 350 prada sale true religion michael kors purses prada glasses Coach Outlet michael kors outlet online MIZUNO Shop US
Michael Law#
Lisa Calabrese#
Ann Tabares#
Ann Tabares#
Ann Tabares#
jlgg# cheap basketball shoes sunglasses hut Coach Outlet Store canada goose jacket brand sunglasses flash sunglasses michael kors us michael kors outlet michael kors purses ray ban glasses Coach Sunglasses Outlet paul smith pandora jewelry authentic prada handbags outlet coach sunglasses Free Run coach outlet salomon hiking shoes michael kors outlet online cheap coach purse burberry canada chanel bag moncler outlet louis vuitton uk burberry scarf moncler us michael kors bags outlet coach factory outlet chanel beats by dre coach factory outlet burberry online moncler uk michael kors outlet nike shox huaraches coach outlet basketball jerseys michael kors jet set tote coach outlet nike jordan michael kors ray ban prescription glasses jimmy choo australia michael kors outlet moncler clothing pandora australia coach Oakley Holbrook sunglasses baseball jerseys prada outlet online basketball jerseys shoes online burberry australia prada bags nike outlet sunglasses sm ugg australia pandora charms kate spade bags coach outlet online pandora charms black friday coach outlet asics Australia Oakley Outlet Nike Air Jordan michael kors outlet michael kors outlet kate spade outlet coach outlet online china factory sale coach factory ray ban outlet burberry scarf Kevin Durant Shoes ray ban outlet kate spade bags outlet nike com pandora charms nike shoes australia pandora rings jewelry abercrombie outlet nike air huarache michael kors bags ugg boots michael kors outlet prada outlet online paul smith uk Jordan Retro pandora bracelet Nike Air Max pandora charms nike shox shoes abercrombie outlet hermes bag mcm factory outlet burberry timberland uk hockey jerseys louis vuitton outlet prada us pandora charms uk Longchamp Outlet Billat michael kors outlet nike australia coach australia michael kors outlet nike shoes louis vuitton outlet pandora jewelry moncler sale michael kors outlet Mizuno Running Shoes bercrombie Nederland pandora rings burberry outlet online canada goose sale coach outlet pandora charms sale clearance coach outlet Nike Free prada sunglasses prada bag shoes online sale adidas yeezy boost 350 china wholesale nike jordan shoes moncler jacket burberry outlet canada landinggear ray ban sunglasses michael kors outlet moncler jacket Nike KD 8 official prada site Nike Air Jordan moncler mens jackets prada outlet prada outlet prada outlet online kate spade outlet kate spade outlet michael kors outlet ray ban sunglasses abercrombie us pandora australia burberry outlet ray ban new wayfarer canada goose sale online official michael kors coach outlet ray ban polarized prada outlet online coach handbags coach factory outlet prada purses pandora charms coach bags Burberry outlet online Adidas Yeezy Boost 350 Michael Kors Canada michael kors outlet ray-ban sunglasses louis vuitton factory outlet coach purses michael kors purses outlet ray ban sunglasses Coach Outlet michael kors italy michael kors authentic prada outlet online pandora charms sale air jordan retro michael kors outlet louis vuitton outlet wholesale pandora charms sale online coach handbags coach outlet cheap moncler jacket Michael Kors Outlet mlb shop asics shoes moncler coats pandora uk coach shoes burberry scarf Hugo Boss Outlet coach outlet online michael kors factory outlet michael kors outlet bags pandora charms oakley sunglasses paul smith sale abercrombie outlet michael kors outlet online moncler jacket michael kors uk yeezy boost 350 shoes mk outlet football jerseys oakley outlet michael kors outlet online cheap ray ban sunglasses pandora australia michael kors outlet mk bags pandora bracelet coach carter pandora charms yeezy boost 350 Nike Jordans Michael Kors Outlet Hyperdunk 2016 asics shoes Australia oakley frogskins sunglasses pandora bracelet coach outlet baseball jerseys mk handbags canada goose outlet Ray Ban Outlet michael kors australia prada outlet nike outlet kate spade bags kate spade outlet kate spade air jordan shoes michael kors outlet nike store prada bags outlet burberry canada Hugo Boss Store michael kors outlet prada outlet prices michael kors tote burberry outlet prada handbags burberry online coach purse michael kors outlet coach outlet online longchamp outlet Basketball shoes polo outlet pandora jewelry ray ban prescription sunglasses pandora uk abercrombie & fitch clk benz Abercrombie Fitch authentic prada outlet online prada factory outlet online ralph lauren australia prada online coach factory outlet online prada factory outlet online coach outlet Hermes Outlet michael kors outlet tiffany and co ray-ban sunglasses pandora necklace charms lebron james shoes pandora rings Mizuno Wave Oakley Holbrook Jordan retro moncler down jackets prada outlet online michael kors outlet salomon shoes abercrombie us abercrombie fitch ralph lauren baseball jerseys longchamp outlet snow boots ray ban eyeglasses michael kors coach outlet adidas australia football jerseys kate spade canada mlb store chanel australia ray ban wayfarer Kate Spade Australia abercrombie outlet kate spade outlet online prada outlet online nike air max Coach outlet online Yeezy 350 mcm outlet online michael kors abercrombie paris coach bag oakley sunglasses prada factory outlet online burberry purse coach australia abercrombie outlet us polo online shoes sale tiffany co michael kors online pandora rings abercrombie and fitch Yeezy Boost 350 kate spade outlet burberry australia Chanel bags Outlet prada handbags coach outlet coach outlet kate spade handbags burberry outlet Nike Jordan Shoes pandora rings prada bags on sale abercrombie and fitch polo outlet online coach australia adidas australia CHanel Factory Outlet Cheap Ray Ban ups tracking kate spade handbags michael kors outlet louis vuitton outlet burberry us landing gears abercrombie outlet nike lebron james pandora necklace pandora princess ring sunglasses hut adidas shoes burberry outlet online michael kors handbags prada outlet major league baseball mens sunglasses veronique Billat mlb shop michael kors canada pandora bracelets nike jordan shoes ray ban online landing gear nike basketball shoes prada bags pandora necklaces nfl shop tiffany uk air jordan shoes Pandora Charm coach sunglasses for women prada outlet nike huarache shoes huaraches shoes oakley sunglasses pandora charms sale oakley frogskins coach outlet nike shoes prada sale prada official site Mizuno Shop prada factory outlet kate spade black friday canada goose jacket jordan retro shoes burberry outlet michael kors handbags Coach Outlet Online michael kors totes kate spade coach bags prada bags moncler outlet pandora rings michael kors outlet Mizuno Shop Japan Prada Outlet beats studio nfl jerseys pandora rings sale michael kors outlet michael kors purses prada handbags pandora rings ugg uk ugg slippers kate spade black friday ray ban sunglasses michael kors bags nike australia nike lebron shoes coach diaper bag pandora rings veronique billat Mizuno Shoes Ralph Lauren Polo michael kors outlet rayban aviator michael kors handbags outlet Nike Hyperdunk Shoes pandora rings piumini moncler replica yeezy boost 350 timberland boots michael kors uk michael kors bags jordan shoes official prada site ray ban clubmaster prada outlet online Nike Hyperdunk 2015 Hugo Boss Online mcm outlet michael kors handbags Prada Factory Outlet prada glasses michael kors wallet kate spade outlet ray-ban sunglasses KD 8 shoes coach usa louboutin shoes Jordan Retro Shoes nike id MIZUNO Shop US prada bags coach outlet store Ralph Lauren kate spade ray ban aviator oakley australia ugg australia burberry scarfs Canada Goose Outlet Pandora bracelet michael kors outlet beats headphones michael kors outlet burberry outlet canada nike free run tiffany co prada outlet online michael kors tote kate spade outlet online coach online michael kors black friday moncler jacket mens louis vuitton australia burberry outlet yeezy boost 350 abercrombie and fitch coach factory outlet top sunglasses michael kors purses on sale burberry outlet pandora australia pandora ring sunglasses outlet nike jordan shoes prada outlet coach outlet nike huarache Chanel Outlet huarache nike moncler outlet
Leave a Comment

Post Comment