HTML Encyclopaedia

The hr tag

This tag is used to produce a horizontal rule or line. It is useful for visually separating parts of a page. A basic example of its use appears below.


The tag has 5 attributes that control various aspects of the appearance of the line. These are

  1. align

    This determines whether the line is left, centre (default) or right aligned. The associated values of the attribute are left, center and right. The effect is best illustrated with lines of less than full width. Here are examples of left, centre and right alignment with a line half the window width.




  2. noshade

    This attribute which takes no value specifies that the line be drawn solid rather than the usual "3-D" effect. Here are examples showing the effect, first the usual form then the noshade form. A thicker than normal line is used.



  3. size

    The value of this attribute specifies the line height or thickness in pixels. Here are some examples.

    sizeshadedexample
    5Yes
    15Yes
    10No
    defaultYes

  4. width

    This specifies the line length either in pixels or as a percentage of the available space between the current margins. The first set of examples show left aligned lines of length 20, 40 and 80 pixels.




    and the next set of examples show centrally aligned lines of length 25%, 50% and 75% of the current space.




  5. color

    This is not an HTML 3.2 tag but is supported by IE. As might be expected from the name of the attribute it controls the colour of the line. Here's a red horizontal rule, if your browser understands the attribute.


Browsers
All browsers honour the tag in its basic form. There are significant differences in the following aspects.

  1. Start Position

    MOS3, IE4, NN and ARA start full width horizontal rules at the current indent, this is consistent with the placing of paragraphs and other block elements. IE3 generates full width horizontal rules starting at the left hand window margin and OP2 starts them at a position intermediate between the window margin and the current indent.

  2. Vertical Spacing

    MOS3, IE3, NN, OP2 and ARA generate a full line height gap between successive horizontal rules. IE4 only produces a gap equal to the line height beneath and a full line gap above.

Only IE honours the color attribute.

Decorated and special lines

In practice the use of the attributes is uncommon. Lines decorated with small furry creatures etc., are images and are generated using the <img> tag and a suitable image file. There is, of course, no way of specifying a dotted or dashed line.