|

HTML horizontal line

HTML horizontal line

Let’s take some time today and discuss this awesome feature in HTML “horizontal line.” First of all, you may need to know if HTML “horizontal line” is a tag or an attribute. You can find more about HTML attributes well explained here. In this case, the HTML horizontal line is a block-level element or, in other words, a tag.

It is used to separate contents within a page or create a break within document sections. What is an element in HTML? Please find the answer and more about the HTML element here.

For example, you have a heading followed by a paragraph. Again a heading and then followed by a paragraph. To have a clear distinction between these two parts, you may want to put a horizontal line in between.

Syntax of the HTML horizontal line

<hr>

It’s normally denoted with an empty tag ‘<hr>’. When we say an empty tag, this simply means that we do not need a closing tag.

HTML horizontal line attributes

As discussed on HTML Attributes, we can add attributes to the <hr> to make it more appealing. Let’s discuss some of the attributes used.

Align attribute

This attribute sets the alignment of the horizontal line on a page. It can either be aligned on the left, right, or center.

Example:

<!DOCTYPE html>
<html>
<head>
	<title>HTML horizontal line</title>
	<style type="text/css">
		#dimension{
			width: 500px;
			height: 300px;
			margin: 0 auto;
			border: 1px solid blue;
			border-radius: 5px;
		}
	</style>
</head>
<body>
  <div id="dimension">
   <p><b>This is a html horizontal line, aligned to left</b></p>
	 <hr align="left" width="100px">
	<p><b>This is a html horizontal line, aligned to right</b></p>
	 <hr align="right" width="100px">
	<p><b>This is a html horizontal line, aligned to center</b></p>
	 <hr align="center" width="100px">
</div>
</body>
</html>

Output:

Alignment
Alignment

By default, the horizontal line occupies the whole width within the defined page or section. To avoid this so that we can note the difference, we added another attribute width. Let’s go ahead and discuss this attribute.

Attribute width

This attribute specifies the amount of space that the <hr> will occupy horizontally concerning the page or section.
Example:

<!DOCTYPE html>
<html>
<head>
	<title>HTML horizontal line</title>
	<style type="text/css">
		#dimension{
			width: 500px;
			height: 300px;
			margin: 0 auto;
			border: 1px solid blue;
			border-radius: 5px;
		}
	</style>
</head>
<body>
  <div id="dimension">
   <p><b>This is a html horizontal line,width attribute</b></p>
	 <hr width="150px">
	
	 <hr width="300px">
	
	 <hr  width="400px">
</div>
</body>
</html>

Size attribute

This attribute specifies the height of horizontal line.

<p><b>This is a html horizontal line,size attribute</b></p>
	 <hr size="5px">

Noshade attribute

This attribute does away with the shading effect on the horizontal line.

<p><b>This is a html horizontal line,size attribute</b></p>
	 <hr noshade>

The other attribute is the color attribute. This will only work with the internet explorer browser. Hence we can only use this attribute when we are sure we will load our page on internet explorer only.

Styling the HTML horizontal line using CSS

We can now add more styles to the horizontal line using the cascaded style sheet to make it more attractive. It’s upon our choice whether to use the internal CSS, inline or external CSS.
Let’s look at a scenario where we will use the border property to style the horizontal line element.

<!DOCTYPE html>
<html>
<head>
	<title>HTML horizontal line</title>

	<style type="text/css">
		
		#dimension{
			width: 500px;
			height: 350px;
			margin: 0 auto;
			border: 1px solid blue;
			border-radius: 5px;
		}
      hr.green{
      	border: 1px solid green;
      }
      hr.dashed{
      	border: 1px dashed red;
      }
      hr.dotted{
      	border: 1px dotted red;
      }
      hr.border_radius{
      	border: 5px solid blue;
      	border-radius: 5px
      }
	</style>
</head>
<body>
  <div id="dimension">
   <p><b>This is a html horizontal line,border attribute</b></p>
   <p>Default</p>
	 <hr>
<p>Green color</p>
	 <hr class="green" size="5" >
<p>Dashed</p>
	 <hr class="dashed" size="5" >
<p>Dotted</p>
	 <hr class="dotted" size="5" >
<p>Border Radius</p>
	 <hr class="border_radius" size="5" >
</div>
</body>
</html>

Conclusion

In this tutorial, we have discussed HTML horizontal lines. We can highly use it when we want to display content on the same HTML page but in a distinct manner. The width of this line is 100% by default, and hence we can modify this using the with attribute. The color attribute only works in internet explorer, but that does not limit us in changing the color of the hr. Using CSS, we can modify its color the way we want, not only the color but also other nice features like a border. CSS makes HTML more attractive and fun t work with. Wrapping up, I would recommend you also have a look at the HTML Q tag.

Similar Posts

  • How to compare strings in JavaScript

    When programming in JavaScript, you will encounter various situations where you must compare two strings before performing an operation. For instance, a user can only log in to a website if its name matches the existing names stored in the database. In such situations, the ‘Strict Equality Operator’ compares the strings. The functionality of comparison in JavaScript is not only limited to value-based comparisons. Strings are compared for various reasons. Some of the reasons include the following:

  • What are HTML Attributes

    An attribute is a piece of information that determines the properties of a field. In HTML, attributes provide more information about an element. They define the behavior of an element. They are always defined in the opening tag of an element, and all attributes are made up of two parts: a Name and a Value.

  • |

    How to create a Chrome extension

    Google Chrome extensions are small apps created using HTML, CSS, and javascript to add some special functionality to chrome. Many popular Chrome extensions serve users with a variety of options and functionality. Some of the popular chrome extensions are Grammarly, wappalyzer, etc. These extensions are developed for a single purpose like the Grammarly extension is for writers to check grammar.

  • |

    Top 10 CSS tricks you should know

    CSS is an acronym for Cascaded Style Sheet.  In the modern world, it seems that every business has a functional website. It’s a necessity to make your website professional and also appealing to the human eye. The better your website is, the higher the chances of visitors staying on your website. This is where the power of CSS comes in – styling your web pages.

  • |

    Beginner guide to creating HTML forms

    Html forms are one of the most important HTML tags for interacting with the user. They are used to taking input from the user, and most commonly, the inputs were sent to the server-side for further processing. Forms are used to build contact pages, login pages, etc., on a site. We can collect different types of data using forms such as email addresses, usernames, passwords, phone numbers, credit card numbers, etc. To build an Html form, we need to use the

    tag element of Html.

  • Seaborn Heatmap Size

    A heatmap is used to create a visual depiction of a matrix. It draws a matrix on the graph, with different color hues representing different values. We can utilize the seaborn to generate heatmap plots in the seaborn module.heatmap() function. The default size of the plot may not provide a good picture of the data when depicting a huge matrix.

Leave a Reply

Your email address will not be published. Required fields are marked *