Home  >  Article  >  Web Front-end  >  How to set font color size in html

How to set font color size in html

下次还敢
下次还敢Original
2024-04-11 13:16:191318browse

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 size in html

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:

  • Hex codes starting with #, for example: #ff0000 (red)
  • RGB Value, for example: rgb(255, 0, 0) (red)
  • Color name, for example: 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:

  • absolute units, for example: px (pixels), em (relative units), rem (Units relative to the root element)
  • Relative units, for example: % (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!

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