Home > Web Front-end > Front-end Q&A > How to set font color in html

How to set font color in html

PHPz
Release: 2023-04-24 11:00:23
Original
6240 people have browsed it

How to set font color in HTML

In web design, color is a very important factor. Different colors can create different atmospheres and convey different messages. In HTML, you can add color to the web page by setting the font color to make it richer and more vivid. This article will introduce how to set font color in HTML.

  1. Using color names

In HTML, you can set the font color directly through the color name. For example: "red" means red, "blue" means blue, "green" means green, and so on. The following is a piece of HTML code that uses color names to set font colors:

<p style="color:red;">这段文字的颜色为红色。</p>
<p style="color:blue;">这段文字的颜色为蓝色。</p>
<p style="color:green;">这段文字的颜色为绿色。</p>
Copy after login

It should be noted here that the color names need to be all lowercase. In practical applications, different color names can be selected as needed.

  1. Using RGB values

RGB values ​​are another way to represent colors. RGB represents the color values ​​of red, green and blue respectively. Their values ​​can be adjusted between 0 and 255. By changing the values ​​of these three colors, different colors can be obtained. In HTML, font color can be set through RGB values. The following is an HTML code that uses RGB values ​​to set font color:

<p style="color:rgb(255,0,0);">这段文字的颜色为红色。</p>
<p style="color:rgb(0,0,255);">这段文字的颜色为蓝色。</p>
<p style="color:rgb(0,128,0);">这段文字的颜色为绿色。</p>
Copy after login

It should be noted here that the RGB value needs to be enclosed in parentheses, and the three numbers are separated by commas, and the color name and RGB value The code location needs to be placed in the style attribute.

  1. Use hexadecimal notation

You can also use hexadecimal values ​​to represent colors. The hexadecimal notation used in HTML consists of six numbers or letters, the first two representing the red value, the middle two representing the green value, and the last two representing the blue value. Each number or letter can take a value between 0 and F, where the number 0 and the letter a represent the smallest color value, and the number F and the letter F represent the largest color value. The following is an HTML code that uses hexadecimal notation to set the font color:

<p style="color:#FF0000;">这段文字的颜色为红色。</p>
<p style="color:#0000FF;">这段文字的颜色为蓝色。</p>
<p style="color:#008000;">这段文字的颜色为绿色。</p>
Copy after login

It should be noted here that the hexadecimal notation requires the pound sign # as a prefix, and the letters in the notation Must be capitalized.

In addition, it should be noted that the method of setting font color in HTML can be applied to various HTML tags, including paragraphs, titles, links, etc.

Summary:

In web design, color is a very important factor. By setting the font color, you can enrich the color and atmosphere of the web page and make it more vivid and active. In HTML, font color can be set in a variety of ways, including color name, RGB value, hexadecimal notation, etc. No matter which method is used, it needs to be set in the style attribute. Different colors usually represent different emotions and information, so when designing a web page, you need to choose according to actual needs.

The above is the detailed content of How to set font color in html. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template