HTML <b> 标签用于突出显示文本并以粗体指定文本。<b> 标签或元素的目的是引起人们对元素内容的注意,这些内容通常不会被赋予特别的重要性。
如果我们在段落元素中编写内容,但内容中出现了一个重要的词,我们可以使用 <b> 标签来突出显示该重要词。
语法
<b> ... </b>
属性
<b> 标签示例
下面的例子将说明<b> 标签的用法,在哪里、何时以及如何使用加粗句子中的任何特定文本。
创建粗体文本
我们可以使用 CSS 或 HTML 制作任何文本元素,这里我们将使用 <b> 标签将文本加粗。
<!DOCTYPE html>
<html>
<body>
<p>This is normal para</p>
<p>
<b>This is bold paragraph </b>
</p>
</body>
</html>
<b> 标签使用 class 属性
我们可以使用标签选择器选择元素,但是当我们在该场景中有多个相同的标签时,我们需要使用 HTML 类属性来选择元素。
<!DOCTYPE html>
<html>
<head>
<style>
.term {
color: green;
font-style: italic;
}
</style>
</head>
<body>
<p>
The two most popular science courses offered by the
school are <b class="term">chemistry</b>
(the study of chemicals and the composition of substances)
and <b class="term">physics</b>
(the study of the nature and properties of matter and energy).
</p>
</body>
</html>
创建不带 <b> 标签的粗体文本
我们也可以创建没有 <b> 标签的粗体文本,为此我们必须使用 <strong> 标签或 CSS font-weight 属性。在这里,我们将使用CSS。
<!DOCTYPE html>
<html>
<body>
<h2>Using CSS properties to set the bold text. </h2>
<p>
This is normal text - <span style="font-weight:bold;">
and this is bold text</span>.
</p>
</body>
</html>
设置 <b> 标签的样式
我们可以使用 <b> 标签将任何单词设为粗体,默认该关键字将加粗以添加更多样式,我们也可以使用 CSS。
<!DOCTYPE html>
<html>
<head>
<style>
b {
color: red;
font-style: italic;
}
</style>
</head>
<body>
<p>
This article describes several <b>text-level</b>
elements. It explains their usage in an
<b>HTML</b> document.
</p>
Keywords are displayed with the default style
of the <b>element, likely in bold. </b>
</body>
</html>
支持的浏览器
浏览器 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
<b> | Yes | Yes | Yes | Yes | Yes |