HTML <font> 标签用于指定文本的字体。我们可以使用此标签和相应的属性来更改颜色、大小和字体。
不再推荐使用 <font> 标签,因为它在 HTML5 中已被弃用。我们可以使用 CSS 属性来更改字体大小、颜色等,而不是使用此标签。
语法
<font size=" " color=" " face=" "> ....</font>
属性
<font> 标签支持 HTML 的 全局属性 和 事件属性。还获得了下面列出的一些特定属性。
属性 | 值 | 描述 |
---|---|---|
color |
rgb(x,x,x) #hexcode colorname |
已弃用 - 指定文本的颜色。 |
face | List of font names | 已弃用 - 指定字体系列。 |
size | number | 已弃用 - 指定 1 到 7 之间的字体大小。 |
HTML <font> 标签示例
下面的例子将说明<font> 标签的用法。在哪里、何时以及如何使用<font> 标签,以及我们如何使用属性来操作字体
设置文本大小
在此示例中,我们将使用 size 属性来更改字体文本大小,以及使用 CSS 更改字体大小的替代方法。
<!DOCTYPE html>
<html>
<head>
<title>HTML font Tag</title>
</head>
<body>
<!-- Using attribute -- >
<font size = "5">
The HTML font tag is now deprecated.
You should use start using CSS to set
font size and family.
</font>
<!-- Using CSS -- >
<p style="font-size:24px">
The HTML font tag is now deprecated.
You should use start using CSS to set
font size and family.
</p>
</body>
设置文本的颜色
在此示例中,我们将使用 color 属性来更改字体文本颜色,以及使用 CSS 更改字体颜色的替代方法。
<!DOCTYPE html>
<html>
<head>
<title>HTML font Tag</title>
</head>
<body>
<!-- Using attribute -- >
<font color = "#ff9900">
The HTML font tag is now deprecated.
You should use start using CSS to set
font size and family.
</font>
<!-- Using CSS -- >
<p style="color:#ff9900">
The HTML font tag is now deprecated.
You should use start using CSS to set
font size and family.
</p>
</body>
</html>
设置文本的字体
在此示例中,我们将使用 face 属性来更改字体文本字体,以及使用 CSS 更改字体字体的替代方法。
<!DOCTYPE html>
<html>
<head>
<title>HTML font Tag</title>
</head>
<body>
<!-- Using attribute -- >
<font face = "cursive,serif">
The HTML font tag is now deprecated.
You should use start using CSS to set
font size and family.
</font>
<!-- Using CSS -- >
<p style="font-family: cursive,serif;">
The HTML font tag is now deprecated.
You should use start using CSS to set
font size and family.
</p>
</body>
</html>
支持的浏览器
浏览器 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
是否支持 | Yes | Yes | Yes | Yes | Yes |