Bold Tag in HTML
Overview
While making a webpage, often we want the reader's attention. We can do this by using Bold text. To make some text bold, we use Bold tags (<b>). It is known as a Boldface element. It is used for representation purposes only and not to convey any semantic message.
Syntax
Attributes
Bold tag in HTML supports Global Attributes like every other HTML Tag. Some of the global attributes that the bold tag in HTML supports are :-
Attribute | Description |
---|---|
accesskey | It is used to specify a keyboard shortcut to activate or focus the element. |
autocapitalize | It is used to control if the input is auto capitalized or not. |
autofocus | It is used to indicate that the element should be focused. |
class | It is used to assign a class name to an element. |
contenteditable | It is used to indicate if the content of an element is editable by the user. |
contextmenu | It is used to specify a context menu for an element. |
data | It is used to store custom data specific to the page, for an element. |
dir | It is used to specify the direction of the element's text. |
draggable | It is used to specify whether an element is draggable or not. |
dropzone | It is used to specify whether the dragged data is copied, moved, or linked, when dropped. |
hidden | It is used to indicate if the element is not yet, or is no longer, relevant. |
id | It is used to specify a unique ID for an element and it must be unique in the whole document. |
lang | It is used to specify the primary language for the element's text content. |
spellcheck | It is used to specify whether the element may be checked for spelling errors or not. |
style | It is used to specify inline style information for an element. |
tabindex | It is used to specify the tabbing order of an element. |
title | It contains text representing advisory information related to the element it belongs to. |
translate | It is used to specify whether the text content of an element should be translated or not. |
Bold tag in HTML mostly supports all the Event Attributes, but some of the Event attributes have certain rules which may apply to the specific tag. Some of the Event Attributes that the bold tag in HTML supports are:-
Attributes | Attributes | Attributes | Attributes |
---|---|---|---|
onabort | ondragover | onloadeddata | onreset |
onblur | ondragstart | onloadedmetadata | onresize |
oncancel | ondrop | onloadstart | onscroll |
oncanplay | ondurationchange | onmousedown | onsecuritypolicyviolation |
oncanplaythrough | onemptied | onmouseenter | onseeked |
onchange | onended | onmouseleave | onseeking |
onclick | onerror | onmousemove | onselect |
onclose | onfocus | onmouseout | onslotchange |
oncontextmenu | onformdata | onmouseover | onstalled |
oncopy | oninput | onmouseup | onsubmit |
oncut | oninvalid | onpaste | onsuspend |
ondrag | onkeydown | onpause | ontimeupdate |
ondragend | onkeypress | onplay | ontoggle |
ondragenter | onkeyup | onplaying | onvolumechange |
ondragexit | onlanguagechange | onprogress | onwaiting |
ondragleave | onload | onratechange | onwheel |
How to use <b> tag in HTML??
Bold tag (<b>) in HTML is used to make text bold. We use it when we want to emphasise something and want the attention of the reader. HTML provides us with <b> tag to format and style text.
- We use bold tags in HTML to bold keywords in a passage, or to create contrast between the Headline and the Body.
- Strong tags are very similar to Bold tags, we will discuss them in the next part.
- We can use the class attributes with bold tags. We can then style it using the class attributes and CSS and we can also add semantic information.
Difference between HTML < b > and < strong > Tags
Bold Tag | Strong Tag |
---|---|
The bold tags (<b>) are used just to make a piece of text visually bold in HTML. | The strong tags (<strong>) are used to format text in HTML and show the importance of a certain part of the text by semantically highlighting it. |
The bold tag was made to display the text in bold, so they are used to gain the reader's attention. | The strong tags emphasise the text while also making it bold. Strong tags help the HTML to understand what is important. |
The bold tags are preferred where we only want to bold a text. | An application of strong tags is beautifully shown by browsers made for blind people. The browser can easily understand what part is more important, and what to emphasise. The strong tags are preferred where we want to emphasise a certain part of the text. |
Examples
Example 1: Simple Use of < b > Tag
Let us start with a simple example of bold tags.
Example
Output
Example 2: Difference between < b > and < p > Tags
Now, let us compare normal paragraph and bold tags.
Example
Output
Example 3: Difference between < b > and < strong > Tags
Let us see a comparison of <strong> and <b> tags.
Example
Output
CSS to Set Bold Text
Now, let us try to bold text using CSS.
Example
Output
Browser Support
The bold tag in HTML is supported by all modern browsers. Some browsers which support bold tags are :-
- Chrome (version >=1)
- Firefox (version >=1)
- Internet Explorer (version >=2)
- Edge Mobile
- Opera
- Opera Mobile
- Safari Mobile
- Samsung Internet
Related Tags
Some related Topics:
Conclusion
- Bold text is an important part of formatting. A bold tag in HTML is used to gain the reader’s attention by bolding the text.
- Strong tag <strong> is used to show its importance.
- We may use these methods to format text and make it bold:
- using <b> tag
- using <strong> tag
- using CSS font-weight