change color of hr

Change HR Color Instantly

By Olivia Rodriguez
AD

Changing the color of the horizontal rule (HR) element in HTML can significantly enhance the aesthetics and functionality of your webpages. The HR element is a line that separates sections of a webpage. By default, it's a straight, solid, dark gray line. However, with a bit of CSS, you can customize its color, width, style, and more, to better match your webpage's design. Let's delve into how you can do this.

Before we proceed, ensure you have the basic understanding of HTML and CSS. If not, there are numerous online tutorials that can help you get started. Now, let's discuss how to change the color of an HR element.

Using Internal Styles

One of the simplest ways to change the color of an HR element is by using inline styles. This involves directly applying CSS properties to your HR element. Here's an example:

AD
Exploring the HR Effect: Transforming Workplaces
Exploring the HR Effect: Transforming Workplaces
Photoshop Hue/Saturation effect | how to change and replace color in photoshop
Photoshop Hue/Saturation effect | how to change and replace color in photoshop
the hr tree is shown in blue and white, with information about its branches on it
the hr tree is shown in blue and white, with information about its branches on it

<hr style="border-color: purple;">

单一 HR 线条

In the above snippet, we've changed the color of the HR line to purple. You can replace 'purple' with any color name, hex code, or RGB value you prefer. Here are a few more examples:

the differences between hr and hrr infographics in an infographtion poster
the differences between hr and hrr infographics in an infographtion poster
a hand drawn diagram with the words hrp's and other things on it
a hand drawn diagram with the words hrp's and other things on it
11 HR Trends for 2026: Shaping What’s Next
11 HR Trends for 2026: Shaping What’s Next

<hr style="border-color: #ff0000;"> (Red)

<hr style="border-color: rgb(0, 128, 0);"> (Green)

AD

多个 HR 线条

If you want to change the color of multiple HR lines, you can apply a class name instead of inline styles. This improves your code's readability and maintainability. Here's how you can do it:

HR Roles and Responsibilities.
HR Roles and Responsibilities.
Diploma of Human Resources Management
Diploma of Human Resources Management
the hr growth garden is shown in this graphic, which shows how it's different stages
the hr growth garden is shown in this graphic, which shows how it's different stages
the 7 types of change management that you should use to manage your organization's needs
the 7 types of change management that you should use to manage your organization's needs
Hair Colours Shades, Redken Color Swatches, Different Hair Highlights Colour, Womens Hair Highlights, Ash And Red Hair, Trending Hair Highlights, Hair Colour Red Brown, Redken Shades Eq Swatches, Ash Red
Hair Colours Shades, Redken Color Swatches, Different Hair Highlights Colour, Womens Hair Highlights, Ash And Red Hair, Trending Hair Highlights, Hair Colour Red Brown, Redken Shades Eq Swatches, Ash Red
HR Induction PowerPoint PPT Template
HR Induction PowerPoint PPT Template

First, define your CSS in the <head> section of your HTML file:

<style> .custom-hr { border-color: #0066ff; } </style>

AD

Then, in your HTML body, apply the class to your HR elements:

How to change colour in crochet? 🔥🔥
How to change colour in crochet? 🔥🔥
the word hr surrounded by words related to it in blue and gray on a white background
the word hr surrounded by words related to it in blue and gray on a white background
10 Steps to Lead a Successful HR Transformation
10 Steps to Lead a Successful HR Transformation

<hr class="custom-hr">

Now, all HR elements with the class 'custom-hr' will be blue (#0066ff). You can adjust the CSS as per your design needs.

AD

Using CSS in a Separate Stylesheet

For larger projects, it's recommended to keep your styles in a separate stylesheet. This improves your code's organization and scalability. Here's how you can do it:

First, create a new CSS file (e.g., styles.css) and link it to your HTML file:

<link rel="stylesheet" href="styles.css">

Then, in your styles.css file, define the styles for your HR elements:

hr { border-color: #00008B; }

Now, all HR elements in your HTML file will be navy blue (#00008B). You can add more CSS rules to this selector for other styles, such as width, thickness, or style (dashed, dotted, etc.).

Remember, the changes you make will only apply to the HR elements in the same directory and its subdirectories. If you want to change the HR style globally, you need to place the CSS rule in your main stylesheet.

Experimenting with different colors and styles can help you find what works best for your webpage. As a final piece of advice, ensure your HR color stands out from your text and background colors for better readability and accessibility.

AD