Changing the color of an hr element
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
The <hr> tag in HTML is used for creating a horizontal rule, or line, which serves as a thematic break between paragraphs of text. By default, the appearance of an <hr> tag is fairly straightforward — typically a horizontal line across the container. However, modern CSS provides several properties to enhance and modify the visual presentation of an <hr> element, including its color.
Changing the Color Using CSS
Changing the color of an <hr> element with CSS can be done in a few ways, depending mainly on your design requirements and the specific styling approach you are adopting. Below are several methods to achieve this.
Using the color Property
The simplest way to change the color of an <hr> is to use the color property. This method generally affects the border color, since an <hr> is traditionally represented by its border.
Using the border-color Property
For more specific control over the borders, you might prefer using the border-color property. This is particularly useful when you have customized the border styles.
Using Background Color with background-color
When you style an <hr> to have a solid look by removing the border and using background color, here’s how you would change its color:
Advanced Styling
Creating Gradient Color
With trends leaning towards more visually appealing design elements, you might want to implement a gradient color on your <hr>.
Adding Transparency
For a more subtle design, you might add transparency to the color of your <hr> using RGBA color values.
Usage Considerations
When changing the color of an <hr> tag, consider the overall design of your website or application to ensure it complements other elements. Consistency is key in design.
Summary Table
| Property | Purpose | Example Value |
color | Sets border color | color: blue; |
border-color | Specifically alters border color | border-color: red; |
background-color | Changes the element's color | background-color: green; |
background (for gradients) | Applies a gradient background | linear-gradient(to right, red, yellow); |
rgba() (for transparency) | Adds color with transparency | rgba(255,0,0,0.5); |
This guide highlights basic and advanced methods for changing the look of an <hr> element, demonstrating how easily you can customize this standard HTML feature to fit your design needs.

