Let's talk about how to set font color and font size in HTML

PHPz
Release: 2023-04-13 14:58:51
Original
9107 people have browsed it

Based on HTML, setting font color, font size and other styles is a common requirement. This article will introduce how to set font color and font size in HTML.

1. Setting the font color in HTML

In HTML, you can use the style attribute to set the color for text. For example, you can use the style attribute to set the text color within a paragraph. As shown below:

<p style="color:red;">这是红色的文本。</p>
Copy after login

In this example, we use the style attribute to specify the text color as red. Note that the color value is enclosed in quotes, because in HTML, attribute values ​​must be enclosed in quotes.

In addition to red, HTML also supports many other colors. Colors can be specified using color names or color codes. For example:

<p style="color:blue;">这是蓝色的文本。</p>
<p style="color:#ff0000;">这是红色的文本。</p>
Copy after login

In the second example, we use the color code #ff0000 to set the text color to red. Other color codes can be found online.

2. HTML setting font size

In HTML, you can use the style attribute to set the font size for text. For example, you can use the style attribute to set the text font size within a paragraph. As shown below:

<p style="font-size:36px;">这是36像素的字体。</p>
Copy after login

In this example, we use the style attribute to set the text font size to 36 pixels. Note that the font size value is in quotes and uses "px" to represent pixels. Other units can also be used, such as em, rem, etc.

In addition to pixels, HTML also supports other font size units. For example:

<p style="font-size:2em;">这是2个em的字体。</p>
Copy after login

In this example, we use em units to set the text font size. em is calculated relative to the current element's font size.

Summary

The style attribute of HTML can be used to set the color and font size of text. Text color can be set using a color name, color code, or other color value. Text font size can be set using units such as pixels, em, rem, etc.

I hope this article will be helpful to you. For more HTML-related knowledge, please pay attention to our website.

The above is the detailed content of Let's talk about how to set font color and font size in HTML. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template