To change font color in HTML, you can use a CSS style sheet to set the color value by specifying a hexadecimal code, RGB value, RGBA value, or color name through an inline style, CSS class, or CSS ID. In HTML5, it is also possible to set the font color on an HTML element directly using the color attribute, but this method only works in modern browsers.
How to change the font color in HTML
To change the font color in HTML, you can use a CSS style sheet, The specific steps are as follows:
1. Use inline style
style
attribute in the HTML element to specify the color value, as follows Display: <code class="html"><p style="color: red;">这是红色的文本。</p></code>
2. Use CSS class
color
attribute to specify the color value , as follows: <code class="css">.my-red-text { color: red; }</code>
<code class="html"><p class="my-red-text">这是红色的文本。</p></code>
3. Use CSS ID
color
property like this: <code class="css">#my-unique-id { color: red; }</code>
<code class="html"><p id="my-unique-id">这是红色的文本。</p></code>
Color value
You can specify the color value using the following format:
#FF0000
means red. rgb(255, 0, 0)
also represents red. rgba(255, 0, 0, 0.5)
represents red with 50% transparency. red
, green
, blue
. Font color in HTML5
In HTML5, you can also use the color
attribute to set the font color directly on the HTML element, As shown below:
<code class="html"><p color="red">这是红色的文本。</p></code>
However, this method only works in modern browsers and is not supported by all browsers.
The above is the detailed content of How to change font color in html. For more information, please follow other related articles on the PHP Chinese website!