HTML - <b> 標籤



HTML <b> 標籤用於突出顯示文字並指定文字為粗體。<b> 標籤或元素的目的是吸引人們注意元素的內容,這些內容通常沒有特殊的重要性。

如果我們在段落元素內編寫內容,但內容中出現了一個重要的單詞,我們可以使用 <b> 標籤來突出顯示該重要單詞。

語法

<b> ... </b>

屬性

HTML b 標籤支援 HTML 的全域性事件屬性。

HTML 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 class 屬性來選擇元素。

<!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> 標籤的情況下建立粗體文字,為此,我們必須使用 HTML <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>

設定 HTML <b> 元素的樣式

我們可以使用 HTML <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>

支援的瀏覽器

標籤 Chrome Edge Firefox Safari Opera
b
html_tags_reference.htm
廣告