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
1228 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:

<code class="html"><p style="color: red;">This is red text.</p></code>
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:

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

Id:

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

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

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>
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:

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

RGB:

<code class="html"><p style="color: rgb(255, 0, 0);">This is red text.</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