Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the color of an hr element

Tags:

html

css

I want to change the color of my hr tag using CSS. The code I've tried below doesn't seem to work:

hr {     color: #123455; } 
like image 831
koool Avatar asked Jun 17 '11 06:06

koool


People also ask

What is HR color?

The default color of hr is black color.

Can you style hr in HTML?

Yes, start with <hr> in HTML.

How do I make my HR tag lighter?

So if your background is for instance white ( #fff ) you can always make your HR very light. Like #eee . And use a CSS file instead of in-line styles. They provide a central definition for the whole site not just a particular element.


2 Answers

I think you should use border-color instead of color, if your intention is to change the color of the line produced by <hr> tag.

Although, it has been pointed in comments that, if you change the size of your line, border will still be as wide as you specified in styles, and line will be filled with the default color (which is not a desired effect most of the time). So it seems like in this case you would also need to specify background-color (as @Ibu suggested in his answer).

HTML 5 Boilerplate project in its default stylesheet specifies the following rule:

hr { display: block; height: 1px;     border: 0; border-top: 1px solid #ccc;     margin: 1em 0; padding: 0; } 

An article titled “12 Little-Known CSS Facts”, published recently by SitePoint, mentions that <hr> can set its border-color to its parent's color if you specify hr { border-color: inherit }.

like image 148
Anton Strogonoff Avatar answered Oct 14 '22 01:10

Anton Strogonoff


  • border-color works in Chrome and Safari.
  • background-color works in Firefox and Opera.
  • color works in IE7+.
like image 43
Cameron Avatar answered Oct 13 '22 23:10

Cameron