Your typical horizontal rule <hr/> is just a boring line shape that slides across the page, unassuming, thoroughly bland and insignificant, as shown in Figure A below. Horizontal rules are the emphatic break between sections of content, and it has been given a bad reputation, so it’s time we spruce up the element just a bit. In this tutorial, I am going to show you how to add unique styles to your horizontal rules <hr />. I will be using Dreamweaver CS5 to edit my html and CSS3, but any text editor will do. A series of screen captures and a demo page will illustrate the steps to creating customized horizontal rules for your web pages.
There are endless options to styling our sore thumb <hr/> tag, and they include any manner of CSS and CSS3 colors, sizes, heights, widths, borders, shapes, and images that can be applied to create imaginative horizontal lines. Let’s start out with some simple CSS — adding in a color first. I will create a quick style class and call it hline_color, give it a nice copper patina color #CFF, and a little height of 2px. The html and CSS snippets of code are displayed below, along with the resulting display as shown in Figure B below.
<hr class="hline_color" />
Now, let’s create a horizontal rule with border styling; the options include dashed, solid, inset, dotted, double, grove, and ridge. The first border example is the dashed styling, the HTML and CSS code snippet, and display are shown below.
<hr class="border" />
border: 2px dashed #000;
Of course, you can add any color to the border you wish, so if we update the color to a shade of #999 where border: 2px dashed #999; then we get the following result as displayed in Figure D:
The double border line style snippet and display:
border: 4px double #999;
The dotted border line style with a new height and color:
border: 1px dotted #606;
CSS3 linear gradient
Let’s add some panache and elegance to our tiny <hr /> using cross-browser support for background image gradients. The gradient starts with a background color of #63C, and then linear gradients are provided for webkit, moz, ms, and o, starting from the left at #C9F, going to the #63C in the middle, then gradient back to #C9F on the right side. The CSS3 snippet and resulting display are shown below.
background-image: -webkit-linear-gradient(left, #C9F, #63C, #C9F);
background-image: -moz-linear-gradient(left, #C9F, #63C, #C9F);
background-image: -ms-linear-gradient(left, #C9F, #63C, #C9F);
background-image: -o-linear-gradient(left, #C9F, #63C, #C9F);
CSS3 drop shadow
Add the shadow-box styling and you create a nice horizontal rule with shading inset and rgb color with a transparency set to 0.8, along with a border-radius of 5px along each of the four corners. The CSS3 code snippet and the resulting display are shown below.
box-shadow: inset 0 9px 9px -3px rgba(141,179,134,0.8);
CSS3 flared edges
In this example, we will add a flared edge to the horizontal rule with two curved flares jutting out toward the top and bottom from each end. Inspiration for this and the next style comes from Chris Coyier and his CSS-Tricks website. The flare utilizes several border properties, a style of ridge, a color of #900, a width of 2px 0 0 0, and a radius of 45px. The before styling sets the display to block, content to “”, height to 50px, and the same border styling properties. The code snippet and resulting display are shown below.
border-width: 2px 0 0 0;
border-width: 0 0 2px 0;
CSS3 double line with symbol
The double border with symbol employs the use of padding at 0, border set to none, border top medium double with #333 color, color set again to #333, and text align set to center. Along with an after styling with properties for content includes the § symbol, display set to inline-block, position is relative, top set to -0.7em, font size is 1.5em, padding set to 0 0.25em, and background set to white. The styling code snippet and resulting display is shown below.
border-top: medium double #333;
padding: 0 0.25em;
There are so many more ways to style a horizontal rule, this just scratches the surface. Do you have any horizontal rule styles that add a unique elegance to your websites? Please share them with us!