Explain Codes LogoExplain Codes Logo

How do I make text bold in HTML?

html
semantic-markup
css
accessibility
Nikita BarsukovbyNikita Barsukov·Sep 9, 2024
TLDR

To underline significance or importance, use the <strong> tag; alternatively, for visually bold styling, use the <b> tag:

<strong>Crucial information.</strong> <b>Bold for aesthetics.</b>

The <strong> tag denotes importance, while <b> highlights visual boldness. Both will render your text as bold.

Difference between <strong> and <b>

While both <strong> and <b> tags make your text bold, there's a considerable difference rooted in semantics. Information conveyed within <strong> tags portray special significance that is acknowledged by tools like search engines and screen readers.

How to use CSS for bold text styling

For more control over text boldness, or when you need bolding for more complex text segments, you could opt for using CSS:

/* Puns are bold in the land of fonts! */ .bold-text { font-weight: bold; }
<!-- This word doesn't just tango, it dances flamenco! --> <p>This is a <span class="bold-text">bold</span> word.</p>

The font-weight: bold; CSS property allows you to customize an array of text elements at once, leading to cleaner, more maintainable code.

Bold Text and Accessibility

As you bold your text, also consider accessibility. For those with visual impairments, the method of bolding text could affect their reading experience due to contrast or emphasis. So, rather than relying solely on boldness to convey information, ensure that meaning is also derived from the actual text content and structure.

Crafting structured markup

Remember that structured content isn't just for human readability—it also aids SEO and accessibility. Use correctly nested heading levels for greater clarity (<h1>, <h2>, and so on), and employ semantic markup (<label>, <th>, <cite>), appropriately to convey additional meaning.

Consider the following markup example:

<!-- You're important, you get a "H1". --> <h1>Main Page Title</h1> <!-- Parenting 101: Always be lesser than your children. --> <h2>Section Header</h2> <label for="search">Search:</label> <th>Table Header</th> <cite>Referenced Work</cite>

Structured HTML and semantic meaning are the dynamic duo of web development – remember to use HTML and CSS for their intended purposes: semantics for meaning and CSS for styling.