The Wayback Machine - https://web.archive.org/web/20240715062549/https://www.geeksforgeeks.org/how-to-add-horizontal-line-in-html/
Open In App

How to add horizontal line in HTML ?

Last Updated : 25 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Creating a visually appealing and well-structured webpage often involves the use of horizontal lines. These lines help separate different sections of content, making it easier for users to read and understand the information presented. In this guide, we’ll explore two effective methods to add horizontal lines in HTML: using the <hr> tag and CSS properties.

Different Approaches to Add Horizontal Line in HTML

1. Using <hr> tag:

The Horizontal Rule tag (<hr>) is used to insert horizontal lines in the HTML document to separate sections of the document. It is an empty or unpaired tag, meaning there is no need for a closing tag.

Example: This example describes the  <hr> tag to add the horizontal line.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>Horizontal line </title>
</head>

<body>
    <h2>Horizontal line using various attributes</h2>
    <hr width="100%" size="2">
    <hr width="100%" size="2" color="blue" noshade>
    <hr width="100%;" color="red" size="5">
</body>

</html>

Output:

HTML horizontal line using hr tag

Output

2. Using CSS Properties:

In this approach, we will use the border-style property to create the horizontal line. You can use either the border-top property, which specifies the style of the top border, or the border-bottom property, which sets the style of the bottom border of an element. Both properties can be used to add a horizontal line.

Example: This example describes the drawing of the horizontal line using the border-style Property.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>Horizontal line using CSS Properties</title>
    <style>
        .horizontal_line {
            width: 90%;
            height: 5px;
            border-top: 5px dotted black;
            line-height: 80%;
        }

        .line {
            border-bottom: 5px solid red;
            margin-top: 5px;
            width: 90%;
        }
    </style>
</head>

<body>
    <h2>Horizontal line using CSS Properties</h2>
    <h3>dotted horizontal line</h3>
    <div class="horizontal_line"></div>
    <h3>Plain horizontal line</h3>
    <div class="line"></div>
</body>

</html>

Output:

horixontal line using CSS example output

Output

Adding horizontal lines to your HTML document is a simple yet effective way to improve the visual structure and readability of your webpage. Whether you choose to use the <hr> tag for a quick and easy solution or CSS properties for more control over the appearance, both methods can help you create a well-organized and aesthetically pleasing layout. Mastering these techniques will enhance your web design skills and contribute to a better user experience on your website.



Similar Reads

How to use complete horizontal line space in HTML ?
In this article, we will create a complete horizontal line space using HTML. To create the horizontal line space, we will use the &lt;hr&gt; tag. The &lt;hr&gt; tag stands for horizontal rule and is used to insert a horizontal rule or a thematic break in an HTML page to divide or separate document sections. The &lt;hr&gt; tag is an empty tag, and i
2 min read
How to make horizontal line with words in the middle using CSS?
CSS provides the feature of making a horizontal line including words or image in the middle of the webpage to make it attractive. This can be achieved by using simple CSS properties. Syntax: h4:before, h4:after { content: ""; flex: 1 1; border-bottom: 2px solid #000; margin: auto; } Example-1: To make a horizontal line with words in middle &lt;html
1 min read
How to change the color of horizontal line (hr element) using CSS ?
The HTML &lt;hr&gt; tag is used to insert a horizontal rule or a thematic break in an HTML page to divide or separate document sections. The color of the &lt;hr&gt; tag can be set by using the background-color property in CSS. Example 1: In this example, the CSS within the &lt;style&gt; section customizes the &lt;hr&gt; element with a red backgroun
2 min read
How to Create a Horizontal Scrolling Chart.js Line Chart with a Locked Y Axis ?
We will learn how to create a horizontal scrolling Chart.js line chart with a locked y-axis using the ChartJS CDN library. ApproachIn the HTML template, use two &lt;canvas&gt; tags: one to show the y-axis which should be locked in place, and the other to show the line chart itself.Create one &lt;div&gt; tag to wrap the first &lt;canvas&gt; tag (the
4 min read
How to add default horizontal scaling to a canvas-type text with JavaScript?
In this article, we are going to see how to add default horizontal scaling to a canvas-like text in JavaScript. By canvas-like, we mean text written is movable, rotatable, resizable and can be stretched. But in this article, we will add default horizontal scaling. Further, the text itself cannot be edited like a textbox. To make this possible we ar
2 min read
How to Add Horizontal & Vertical Space Between Elements in Tailwind CSS ?
Tailwind CSS simplifies web design with its utility-first approach. Creating websites that look good is important in web development. Tailwind CSS is a tool that helps make this easier. One important thing to learn is how to put space between elements. Below are the approaches to Add Horizontal &amp; Vertical Space Between Elements in Tailwind CSS:
3 min read
How to Add a Line Break with the br Tag in HTML?
The &lt;br&gt; tag in HTML is a simple yet essential element used to insert a line break within a block of text or content. In this article, we'll explore the usage of the &lt;br&gt; tag and discuss various scenarios where it can be effectively applied. Usage of the &lt;br&gt; Tag The &lt;br&gt; tag, also known as the line break tag, is a self-clos
2 min read
How to add line breaks to an HTML textarea?
Line breaks in an HTML textarea refer to the inclusion of newline characters (\n) that separate lines of text within the textarea. When users press Enter or Return, a line break is created, making text easier to read and format within the form element. The way of implementing line breaks differs from one platform to another. The following approach
2 min read
How to horizontal align text content into center in HTML ?
In this article, we will align the text content into center using HTML. We use align="center" attribute to set the text content into center. Syntax: &lt;element_name align="center"&gt; Contents... &lt;element_name&gt; The align="center" attribute is used to set the text content into center. Example 1: C/C++ Code &lt;!DOCTYPE html&gt; &lt;html&gt;
1 min read
How to create Horizontal Scroll Snap Using HTML and CSS ?
In this project, we are going to create a simple Horizontal Scroll Snap by using HTML and CSS only. Glimpse of Project: Approach: The best way to animate the HTML objects is by using CSS classes and by setting the transitions at different stages. HTML code: Create an HTML file (index.html).Link the CSS file in HTML that provides all the animation’s
1 min read
three90RightbarBannerImg