Google was no luck, and also existing hr
color questions, resulting in how to change the hr
color
I want to create a border
with the same color as the default <hr>
color, but I don't know what color is it exactly.
Anyone knows?
p.s. - I know how to change the color of hr tag.. I want to find out what it is before I change it
The default color of hr is black color.
The HTML <hr> color Attribute is used to specify the color of a Horizontal rule.
The <hr /> tag accepts attributes such as width , color , size , and align .
You can simply use the CSS background-color property in combination with the height and border to the change the default color an <hr> element. In the following example we've changed the color of hr tag to light grey. You can also increase the thickness of the line by simply increasing the value of the height property.
The color of the horizontal ruler depends on the browser, but you can get the color of the hr
element like following:
el = document.querySelector("hr");
color = window.getComputedStyle(el).getPropertyValue("border-top-color");
console.log(color);
Note however, that often the border-style
is inset, so the color you get might differ from the "real" value you see on the screen. You either want to:
hr
hr
element to solid
like I did in the demo to get the "real" color hr
-element to and adapt your color accordingly (might be tricky and browserdependent to compute)See a Demo which demonstrates getting the according color.
w3 does not define a default color for the hr element (http://www.w3.org/TR/CSS21/sample.html), html5 default stylesheet is not confirmed yet afaik but should not change this fact.
As a result, each browser is free to apply its own defaults.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With