Home > Web Front-end > CSS Tutorial > How Do I Change the Color of an HTML Horizontal Rule Using CSS?

How Do I Change the Color of an HTML Horizontal Rule Using CSS?

Susan Sarandon
Release: 2024-12-11 17:39:19
Original
882 people have browsed it

How Do I Change the Color of an HTML Horizontal Rule Using CSS?

How to Change the Color of an


Element Using CSS

In HTML, the


tag creates a horizontal line that can be used to separate sections of a web page. By default, this line is gray or black, but you can easily change its color using CSS.

The code you provided doesn't change the color of the line because you are using the "color" property, which affects the text color, not the line color. To change the line color, you should use the "border-color" property.

hr {
  border-color: #123455;
}
Copy after login

This will change the color of the


line to #123455.

Note that changing the "border-color" will affect the entire line, including any padding or margin added to the


element.

If you also want to change the color of the background behind the line, you can use the "background-color" property:

hr {
  border-color: #123455;
  background-color: #efefef;
}
Copy after login

This will change the line color to #123455 and the background color to #efefef.

The above is the detailed content of How Do I Change the Color of an HTML Horizontal Rule Using CSS?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template