To set HTML font color and size, use the following methods: Use the color attribute to set the color, which can be a hex code, RGB value, or color name. Use the font-size property to set the size, which can be absolute (pixels or inches) or relative (em or rem). To set both color and size, use the style attribute and include the color and font-size attributes.
How to set HTML font color and size
Font color
To set the HTML font color, use the color
attribute. This property is followed by a color value, which can be a hexadecimal code, an RGB value, or a predefined color name. For example:
<code class="html"><p style="color: #ff0000;">红色文本</p> <p style="color: rgb(0, 128, 0);">绿色文本</p> <p style="color: blue;">蓝色文本</p></code>
Font size
To set the HTML font size, use the font-size
attribute. This attribute is followed by a size value, which can be absolute (such as pixels or inches) or relative (such as em or rem). For example:
<code class="html"><p style="font-size: 16px;">16 像素文本</p> <p style="font-size: 1.2em;">1.2 倍默认字体大小的文本</p> <p style="font-size: 1.5rem;">1.5 倍根字体大小的文本</p></code>
Set both color and size in one element
To set both color and size in one element, use style
properties, and include the color
and font-size
properties. For example:
<code class="html"><p style="color: blue; font-size: 16px;">蓝色 16 像素文本</p></code>
The above is the detailed content of How to set font color and size in html. For more information, please follow other related articles on the PHP Chinese website!