Home >Web Front-end >HTML Tutorial >How to set font color size in html
Set font color and size through CSS styles in HTML. Font color is specified using the color property, which can be specified as a hex code, RGB value, or color name. Font size uses the font-size property, which can be specified in absolute or relative units, including pixels, ems, rem, and percentages.
How to set font color and size in HTML
In HTML, you can use CSS styles to set font color and size.
Font color
Use the color
property to set the font color. Colors can be specified as:
#, for example: #ff0000
(red) rgb(255, 0, 0)
(red) red
, blue
, green
Example:
<code class="html"><p style="color: #ff0000;">这是红色的文本。</p> <p style="color: rgb(0, 0, 255);">这是蓝色的文本。</p> <p style="color: green;">这是绿色的文本。</p></code>
font-size
Use font-size
Property sets the font size. Font size can be specified in:
px
(pixels), em
(relative units), rem
(Units relative to the root element) %
(Percentage relative to the parent element) Example:
<code class="html"><p style="font-size: 20px;">这是 20 像素大小的文本。</p> <p style="font-size: 1.5em;">这是相对于父元素大小 1.5 倍的文本。</p> <p style="font-size: 1.2rem;">这是相对于根元素大小 1.2 倍的文本。</p></code>
The above is the detailed content of How to set font color size in html. For more information, please follow other related articles on the PHP Chinese website!