HTML <i> 标签用于以斜体样式显示内容,通常用于不同语言中的重要单词以及技术术语。如果我们在段落元素中编写内容,但内容中出现了重要的单词或不同的语言,我们可以使用 <i> 标签来突出显示重要单词。
语法
<i> content </i>
属性
<i> 标签示例
在下面的例子中,我们将看到 i 元素的不同例子。每个示例都将说明html i标签的用例。
指定斜体元素
在下面的示例中,让我们看看 <i> 标签在 HTML 文档中的用法。
<!DOCTYPE html>
<html>
<body>
<h2>
<i>This one is italic text</i>
</h2>
<p>
I looked at it and thought
<i>This can't be real! </i>
</p>
<p>
The term <i>bandwidth</i> describes the measure
of how much information can pass through a data connection
in a given amount of time.
</p>
</body>
</html>
设置斜体元素样式
考虑以下示例,我们正在创建一个 HTML 文档并使用 <i> 标签创建斜体文本,并使用 style 属性使斜体文本具有样式。
<!DOCTYPE html>
<html>
<head>
<style>
i {
color: red;
}
</style>
</head>
<body>
<h2>
<i>This one is italic text</i>
</h2>
<p>
I looked at it and thought
<i>This can't be real! </i>
</p>
<p>
The term <i>bandwidth</i> describes the measure
of how much information can pass through a data connection
in a given amount of time.
</p>
</body>
</html>
使用斜体元素指示差异语言
让我们看一下另一种情况,我们将在文本中使用 <i> 来表示它是不同的语言。
<!DOCTYPE html>
<html>
<head>
<style>
i {
color: red;
}
</style>
</head>
<body>
<p>
The Latin phrase <i lang="la">Veni, vidi,
vici</i> is often mentioned in music, art,
and literature.
</p>
</body>
</html>
HTML <i> 标签用法
当没有更合适的语义元素时,在任何文本上使用 <i> 标签。例如 <em>、<strong>、<mark>、<cite> 和 <dfn> 标签。
支持的浏览器
浏览器 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
<i> | Yes | Yes | Yes | Yes | Yes |