Home > Web Front-end > HTML Tutorial > How to change font color in html

How to change font color in html

下次还敢
Release: 2024-04-05 09:27:19
Original
1284 people have browsed it

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

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:

<p style="color: red;">This is red text.</p>
Copy after login
Copy after login

2. Use class or id

Use class or id to apply styles to multiple elements. The syntax is as follows:

Class:

<p class="red-text">This is red text.</p>
Copy after login
.red-text {
  color: red;
}
Copy after login

Id:

<p id="red-text">This is red text.</p>
Copy after login
#red-text {
  color: red;
}
Copy after login

3. Use CSS variables

CSS variables can store values ​​and can be used in multiple styles. The syntax is as follows:

:root {
  --text-color: red;
}

p {
  color: var(--text-color);
}
Copy after login

4. Use predefined CSS color values ​​

HTML provides predefined CSS color values, for example:

<p style="color: red;">This is red text.</p>
Copy after login
Copy after login

5. Use hexadecimal or RGB Color value

You can also use hexadecimal or RGB color values, the syntax is as follows:

Hex:

<p style="color: #ff0000;">This is red text.</p>
Copy after login

RGB:

<p style="color: rgb(255, 0, 0);">This is red text.</p>
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
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template