Home >Web Front-end >HTML Tutorial >How to change font color in html
There are five ways to change font color in HTML: use inline style use class or id use CSS variables use predefined CSS color values use hexadecimal or RGB color values
How to change font color in HTML
In HTML, you can change font color in several ways:
1. Use inline styles
Inline styles are directly applied to specific elements. The syntax is as follows:
<code class="html"><p style="color: red;">This is red text.</p></code>
2. Use class or id
Use class or id to apply styles to multiple elements. The syntax is as follows:
Class:
<code class="html"><p class="red-text">This is red text.</p></code>
<code class="css">.red-text { color: red; }</code>
Id:
<code class="html"><p id="red-text">This is red text.</p></code>
<code class="css">#red-text { color: red; }</code>
3. Use CSS variables
CSS variables can store values and can be used in multiple styles. The syntax is as follows:
<code class="css">:root { --text-color: red; } p { color: var(--text-color); }</code>
4. Use predefined CSS color values
HTML provides predefined CSS color values, for example:
<code class="html"><p style="color: red;">This is red text.</p></code>
5. Use hexadecimal or RGB Color value
You can also use hexadecimal or RGB color values, the syntax is as follows:
Hex:
<code class="html"><p style="color: #ff0000;">This is red text.</p></code>
RGB:
<code class="html"><p style="color: rgb(255, 0, 0);">This is red text.</p></code>
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!