How to create a horizontal line (rule) in HTML

What is HTML Horizontal Rule?

In HTML, <hr> (horizontal rule) is a simple horizontal line that appears in different sections of webpage.

The <hr> element is used to create horizontal line in the webpage content.

It is often used to separate sections of webpage content.

Example of Creating HTML Horizontal Rule

Add an <hr> element between the sections where you want to display the horizontal line.

Look at the following example where <h1> and <p> elements are separated by a horizontal line.

Example of Horizontal Rule


Output of the above example

Example of Horizontal Rule in HTML


The above line is a horizontal rule


You can increase the height of horizontal line and change the color of the line.

Following example illustrates the use of CSS height and background-color properties:

Example of Horizontal Rule With Type Attribute


Output of the above example

Example of Horizontal Rule With CSS style


The above line is a horizontal rule with CSS style

Live Code Playground

In the following HTML code editor, you can practice the above code by creating more new HTML horizontal rules. Click on the 'Run Code' button to render the code; the rendered page will be displayed in the following HTML Code Output frame. Practice until you become comfortable and proficient with your code.

HTML logo HTML Online Editor
HTML Code Output