Home > Article > Web Front-end > How to change font color in html
Changing the font color in HTML can be achieved by using CSS (Cascading Style Sheets): specify the color value using inline styles. Use an internal style sheet to define color rules in the
tag. Use an external style sheet to define rules in a separate CSS file and link to the HTML file. Color value formats include: hexadecimal, RGB, RGBA, and color name. In addition to changing the foreground color, you can also set the background color and create a shadow or glow effect using the text-shadow property.
How to change font color in HTML
Changing font color in HTML is a simple process that can This is achieved by using CSS (Cascading Style Sheets). Here's a step-by-step guide:
1. Using inline styles
Use the style
attribute inside an HTML element and specify color
Value:
<code class="html"><p style="color: red;">这是一个红色的段落。</p></code>
2. Use an internal style sheet
to define a <style> within the
tag ;
element and set the font color rule:
<code class="html"><style> p { color: blue; } </style></code>
3. Use an external style sheet
in a separate CSS file (such as style.css
) and then link it to the HTML file using the <link>
element:
<code class="html"><link rel="stylesheet" href="style.css"></code>
Define the rules within the style.css
file:
<code class="css">p { color: green; }</code>
Color Values
HTML and CSS support multiple color value formats:
Other options
In addition to changing the foreground color, you can also change the background color:
<code class="css">p { color: red; background-color: yellow; }</code>
You can use text -shadow
property creates a shadow or glow effect:
<code class="css">p { color: white; text-shadow: 2px 2px 5px #000; }</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!