How to change font color in html

下次还敢
Release: 2024-04-11 07:44:14
Original
662 people have browsed it

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

#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>
Copy after login

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>
Copy after login
<code class="html"><p class="text-red">这是红色文本</p></code>
Copy after login

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:

  • Hexadecimal code: #ff0000 (red)
  • RGB value: rgb(255, 0, 0) (red)

Example:

<code class="html"><p style="color: #ff0000;">这是红色文本</p>

<p class="text-red">这是红色文本</p></code>
Copy after login

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!

Related labels:
css
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template