<b>

Definition

The HTML <b> element is used to represent a span of text that should be rendered in boldface. It is typically used to highlight a word or phrase that has special importance or emphasis.

Examples

Here is an example of how to use the <b> element:

<p>I bought a <b>new car</b> yesterday.</p>

In this example, the word "new" is wrapped in <b> tags, so it will be displayed in boldface.

The <b> element is a structural element, which means that it is used to define the structure of the document, rather than to define the visual appearance of the content. As such, it does not have any built-in styles or formatting. Instead, the visual appearance of the text within the <b> element is determined by the styles applied to it by the user agent (such as the web browser), the user, or the web developer.

For example, the default styling for the <b> element in most web browsers is to display the text in boldface. However, a web developer can override this default styling by using CSS (Cascading Style Sheets) to specify custom styles for the <b> element.

Here is an example of how to use CSS to style the <b> element:

b {
	color: red;
	font-size: 24px;
}

In this example, the <b> element is styled with a red text color and a font size of 24 pixels.

It's important to note that the <b> element should not be used to create visual effects or to define the visual appearance of text. Instead, it should only be used to semantically mark up text that has special importance or emphasis.

For example, if you want to create a boldface effect without using the <b> element, you could use the <strong> element instead. The <strong> element is used to represent text that has strong importance, and it is typically rendered in boldface by default.

Here is an example of how to use the <strong> element:

<p>I bought a <strong>new car</strong> yesterday.</p>

In this example, the word "new" is wrapped in <strong> tags, so it will be displayed in boldface by default. The resulting output would look the same as in the previous example.

In summary, the <b> element is used to represent text that has special importance or emphasis. It should not be used for visual effects or to define the visual appearance of text. Instead, it should be used semantically, to mark up text that has special importance or emphasis.

Attributes

This element makes use of the global attributes.

Best Practices

  • Use the <b> element to indicate text that is stylistically different from the surrounding text, such as keywords or product names.
  • Don't use the <b> element to make text bold. Instead, use the strong element, which conveys the importance of the text.
  • Don't use the <b> element as a substitute for proper semantic markup. For example, don't use it to make a heading bold, use the <h1>, <h2>, etc. elements instead.
  • Avoid using the <b> element if it doesn't add any meaning to the content. In most cases, using a <span> element with a CSS class is a better solution.
  • Don't use the <b> element to create a button or other interactive element. Use the appropriate semantic elements, such as <button> or <a>, instead.

Accessibility Considerations

The <b> element in HTML is used to mark text as bold, without implying any additional importance or emphasis. In terms of accessibility, it is important to use the <b> element in a way that conveys the intended meaning to assistive technologies, such as screen readers. This can be achieved by using the <b> element in combination with other semantic HTML elements, such as <strong>, <em>, and <mark>, to provide context and convey the intended emphasis or importance of the text. Additionally, using CSS styles to control the visual appearance of the text can help ensure that the text is displayed in a way that is accessible to all users.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes