How to change the color of hr tag using CSS

featured Image

Here, we will learn how to change the color of HR element in our HTML using CSS style.

To change the color of the HR tag in our HTML using CSS we have to use the CSS background-color property.

Before starting, let us know a bit about the HR element and why it is used.

HTML < hr > Tag

The <hr> tag stands for horizontal rule (thematic break) and it is used to insert a horizontal line in an Html Page. It is used as a divider or a separator between two HTML components.

Attributesdescription
alignspecify alignment in a hr element
widthuse to give a width to hr element
heightUse to give height to hr element
noshadeno shading effects to hr element
colorUse to set color to hr element

Now to change the color of HR element, you can try any of the methods below:

Method 1: Change the CSS of the HR element

hr { 
  background-color: red; 
  height: 1px; 
  border: none;
}

Method 2 : Using HR attributes

<hr width="70%" size="20" color="red">

Method 3 : With noshade attribute

 <hr width="70%" size="20" noshade>

Some browsers use the color attribute and some use the background-color attribute. So use both color and background-color property when assigning a color to the <hr> tag.

  • border-color : works in Chrome and Safari.
  • background-color : works in Firefox and Opera.
  • color : works in IE7+

Using both color and background-color

hr { 
  background-color: red;
  color: red;
  height: 1px; 
  border: none; 
}

Hope you like the article. Learn More about HR from https://developer.mozilla.org/en-US/docs/Web/HTML/Element/hr

Related Topics:

Detect Dark Mode Using JavaScript And CSS

JavaScript: Change Background Color Of A Webpage

Change Text Color Using JavaScript With Example

Related Posts

featured Image

Disable scrolling Behavior on a body with element on position fixed in mobile

Here in this article, we will learn on how to disable the scroll behavior of the body whenever we scroll over an element whose position is fixed in our mobile…

Read more
featured Image

How to Remove Underline from Links in Bootstrap.

In this article, we will learn how to remove the underline from anchor tags in Bootstrap. Just like any other HTML element, links can also be styled using CSS. We…

Read more
featured Image

How to disable the resizable property of a textarea

In this article, we will see quick ways to disable the resizable property of a textarea using CSS. In CSS, we can disable it using the resize property. Set resize…

Read more

Leave a Reply

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