This is red text
;2. Use an external style sheet and apply CSS classes to multiple elements to define the text color, for example: .text-red { color: red; }This is red text
."/> This is red text ;2. Use an external style sheet and apply CSS classes to multiple elements to define the text color, for example: .text-red { color: red; }This is red text
.">Home > Article > Web Front-end > How to change font color in html
The two main ways to change font color in HTML are: 1. Use inline styles to specify the text color directly in the HTML element, for example:
This is red text
2. Use an external style sheet and apply a CSS class to multiple elements to define the text color, for example: .text-red { color: red; }This is red text
.
#How to change font color in HTML?
In HTML, there are two main ways to change the font color of text:
1. Using inline styles
Using inline styles, you can specify text color directly in the HTML element. The syntax is as follows:
<code class="html"><p style="color: red;">这是红色文本</p></code>
The "color" attribute specifies the text color, and "red" is the color of the text to be changed.
2. Using external style sheets
Using external style sheets, you can apply styles to an entire website or to multiple elements on a page. The syntax is as follows:
<code class="css">.text-red { color: red; }</code>
<code class="html"><p class="text-red">这是红色文本</p></code>
In this case, we have created a CSS class "text-red" that sets the text color of all elements to red. We then apply the class to the paragraph element using the "class" attribute.
In addition to using a color name (such as "red"), you can also specify a color using a hexadecimal code or an RGB value:
Example:
<code class="html"><p style="color: #ff0000;">这是红色文本</p> <p class="text-red">这是红色文本</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!