W3Schools HTML Horizontal Line Complete Guide with Code Examples

The humble yet powerful


tag in HTML allows you to insert horizontal lines, dividing content into clear sections. W3Schools, the renowned learning platform, offers an excellent resource for understanding and implementing this tag. Let's delve into the world of HTML horizontal lines using W3Schools as our guide.

✨ The <hr> Tag – Horizontal Rule
✨ The <hr> Tag – Horizontal Rule

Horizontal lines are often used to separate sections of a web page, creating a visual hierarchy that enhances readability. With W3Schools' comprehensive tutorial, you can master the art of using the


tag, learning about its attributes and even creating responsive horizontal lines.

a computer screen with the text html and an image of a web page on it
a computer screen with the text html and an image of a web page on it

Basic Usage of HTML Horizontal Line

The basic syntax for the horizontal line is straightforward: wrap the


tag within opening and closing tags - e.g.,
. W3Schools demonstrates this with simple, animated examples, making learning a joy.

a web page with the words html and css in green, white and black
a web page with the words html and css in green, white and black

The


tag is a self-closing tag, meaning you don't need to insert a closing tag. However, using it won't cause any errors.

Changing the Thickness of Horizontal Lines

Responsive Horizontal Timeline in HTML CSS
Responsive Horizontal Timeline in HTML CSS

W3Schools shows how to adjust the thickness of the line using the size attribute. For instance,


creates a thicker line than the default. You can specify a value in pixels (e.g., size="10") or use fractions (size="3"), with the fraction representing the default thickness.

Here's a simple example:


The line above has a thickness of 5.

Alignment of Horizontal Lines

an image of a computer screen with many lines and numbers on it, all in different colors
an image of a computer screen with many lines and numbers on it, all in different colors

The align attribute determines how the horizontal line is positioned within its parent element. Possible values are "left", "center", and "right", representing the text alignment. W3Schools provides interactive demonstrations for each alignment, making it easy to understand.

For example:


This line is centered within its container.

Creating Responsive Horizontal Lines

Website 101 - Tìm hiểu các thuật ngữ cơ bản về website
Website 101 - Tìm hiểu các thuật ngữ cơ bản về website

In modern web design, responsiveness is key. W3Schools teaches how to make horizontal lines responsive using CSS. By removing the height and border from the


tag and adding CSS, you can create flexible lines that adapt to various screen sizes.

Here's an example:


In the CSS, you'd define #responsiveLine { border-top: 10px solid #ddd; } to create a responsive line.

W3Schools.com
W3Schools.com
Responsive Horizontal Timeline CSS - Code Snippet
Responsive Horizontal Timeline CSS - Code Snippet
an image of a web page with the words'body'and'reader '
an image of a web page with the words'body'and'reader '
Simple Horizontal List In HTML CSS
Simple Horizontal List In HTML CSS
an image of a computer screen with some text on it
an image of a computer screen with some text on it
an image of a website page with the text'htmls'in white and green
an image of a website page with the text'htmls'in white and green
an image of a website page with the text'html 5 page for seo '
an image of a website page with the text'html 5 page for seo '
Space, Line Break, and Tags in HTML Content
Space, Line Break, and Tags in HTML Content
an image of a computer screen with many lines on the side and one line in the middle
an image of a computer screen with many lines on the side and one line in the middle
a large poster with different types of web pages
a large poster with different types of web pages
CSS Notes for Beginners (Easy + Quick Guide) 🎨
CSS Notes for Beginners (Easy + Quick Guide) 🎨
an image of a web page with the words ordered list in html
an image of a web page with the words ordered list in html
How to Use CSS to Style HR (Horizontal Rule) Tags
How to Use CSS to Style HR (Horizontal Rule) Tags
the instructions for how to draw an animal with numbers and letters on it's side
the instructions for how to draw an animal with numbers and letters on it's side
an image of spider man texting in css scroll snap type with the caption'read caption '
an image of spider man texting in css scroll snap type with the caption'read caption '
About HTML tags
About HTML tags
18 Exciting HTML and CSS Project Ideas with source code to Level Up Your Web Development Skills
18 Exciting HTML and CSS Project Ideas with source code to Level Up Your Web Development Skills
the before and after css web page is shown with an image of two screens
the before and after css web page is shown with an image of two screens
a computer screen with the word headlines on it and an image of two different sections
a computer screen with the word headlines on it and an image of two different sections
CSS Timelines
CSS Timelines

Colorful Horizontal Lines with Border-Bottom

W3Schools also covers using the border-bottom CSS property to create colorful horizontal lines. This method is more versatile as it allows you to adjust height, style, and color.

Sample code: div { border-bottom: 10px solid #ff0000; } creates a red line with a thickness of 10 pixels.

Styling Horizontal Lines with Borders and Gradients

For more elaborate designs, W3Schools demonstrates how to use gradients and borders with the


tag. By applying gradients to the background or border, you can create unique, eye-catching horizontal lines.

Example: hr { background: linear-gradient(to right, #ff0000, #ffff00); } creates a horizontal line with a gradient from red to yellow.

Mastering the


tag is a crucial skill in HTML, and W3Schools provides the perfect platform to learn and practice. With its wealth of examples and interactive coding environment, you can confidently create horizontal lines that enhance the visual appeal of your web pages.

Related Articles

How To Link Pages To Navigation Bar Html W3schools W3schools Html Date W3schools Dropdown Menus W3 Schools Html Code Runner Html Background Image W3 W3schools Html Head How To Change Background Color In Html W3schools W3schools Html Body Background Color W3schools Html Flex Html Input Mask Example