To apply text formatting such as bold, italic, and underline in HTML, you can use various tags and CSS styles. Here’s how you can achieve each formatting style:
- Bold Text: To make text bold, you can use the
<b>
or<strong>
tags. Alternatively, you can use CSS to apply thefont-weight: bold;
property to the desired element. Here are examples of both methods:
Using <b>
tag:
<b>This text will be bold.</b>
Using CSS:
<span style="font-weight: bold;">This text will be bold.</span>
- Italic Text: To make text italic, you can use the
<i>
or<em>
tags. Additionally, you can apply the CSSfont-style: italic;
property to the element. Here are examples of both methods:
Using <i>
tag:
<i>This text will be italic.</i>
Using CSS:
<span style="font-style: italic;">This text will be italic.</span>
- Underline Text: To underline text, you can use the
<u>
tag. However, it’s important to note that underlining text is generally discouraged in modern web design due to its association with hyperlinks. Instead, it’s recommended to use CSS to style your text. Here’s an example:
Using CSS:
<span style="text-decoration: underline;">This text will be underlined.</span>
It’s worth mentioning that using CSS styles gives you more control over the appearance and allows you to apply these formatting styles to any HTML element, not just specific tags.