HTML - <hr> Tag



The HTML <hr> element represents a thematic break between paragraph-level elements: for example, a change of scene in a story or a shift of topic within a section. Or it is displayed as a horizontal rule that is used to separate content (or define a change) in an HTML page.

The <hr> element takes an attribute color that is used for coloring the horizontal line. And this tag supports both global attributes and event attributes in HTML.

Syntax

Following is the syntax of <hr> tag −

<!Doctype html>
<html>
<body>
   <p> …content </p>
   <hr>
</body>
</html>

Example

Let's consider the following example, where we are creating an HTML document that shows the behavior of the <hr> tag.

<!DOCTYPE html>
<html>
<body>
   <p> This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text. This is the first paragraph of text. </p>
   <hr />
   <p> This is the second paragraph of text. This is the second paragraph of text. This is the second paragraph of text. This is the second paragraph of text. </p>
</body>
</html>

When we run the above code, it will generate an output consisting of the text displayed on the webpage along with a horizontal line between them.

Example

In the following example, we are creating an HTML document and modifying the <hr> tag using the CSS properties as follows −

<!DOCTYPE html>
<html>
<head>
   <style>
      hr {
         border: none;
         border-top: 3px double #333;
         color: #333;
         overflow: visible;
         text-align: center;
         height: 5px;
      }

      hr:after {
         background: #fff;
         content: '§';
         padding: 0 4px;
         position: relative;
         top: -13px;
      }
   </style>
</head>
<body>
   <h2>TutorialsPoint</h2>
   <hr>
   <p>§1: The first rule of Fight Club is: You do not talk about Fight Club. </p>
   <hr>
   <p>§2: The second rule of Fight Club is: Always bring cupcakes. </p>
</body>
</html>

On running the above code, the output window will pop up displaying the text along with a CSS applied hr tag on the webpage.

Example

Considering the following example, we are creating an HTML document and using the <hr> tag and its attributes that are not supported in HTML5, as follows:

<!DOCTYPE html>
<html>
<body>
   <h2>TutorialsPoint</h2>
   <hr align="left">
   <p>The first rule of Fight Club is: You do not talk about Fight Club. </p>
   <hr align="noshade">
   <p>The second rule of Fight Club is: Always bring cupcakes. </p>
   <hr size="10">
   <p>This is paragraph! </p>
   <hr width="100">
   <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. </p>
</body>
</html>

When we run the above code, it will generate an output consisting of the text and shows how <hr> tag works in HTML4.

html_tags_reference.htm
Advertisements