Home >Web Front-end >HTML Tutorial >How do you format text as bold, italic, underlined, or strikethrough in HTML?

How do you format text as bold, italic, underlined, or strikethrough in HTML?

Johnathan Smith
Johnathan SmithOriginal
2025-03-19 12:41:20857browse

How do you format text as bold, italic, underlined, or strikethrough in HTML?

Formatting text in HTML to appear as bold, italic, underlined, or strikethrough can be achieved using specific tags. Here's how you can do it:

  • Bold Text: To make text bold, you use the <b></b> or <strong></strong> tags. For example:

    <code class="html"><b>This text is bold.</b>
    <strong>This text is also bold.</strong></code>
  • Italic Text: For italic text, you use the <i></i> or <em></em> tags. For example:

    <code class="html"><i>This text is italic.</i>
    <em>This text is also italic.</em></code>
  • Underlined Text: Underlining text is done with the <u></u> tag. For example:

    <code class="html"><u>This text is underlined.</u></code>
  • Strikethrough Text: To apply a strikethrough effect, use the <s></s> or <del></del> tags. For example:

    <code class="html"><s>This text is strikethrough.</s>
    <del>This text is also strikethrough.</del></code>

These tags should be wrapped around the text you wish to format.

What are the HTML tags used for bold and italic text formatting?

For bold text formatting, the tags used are <b></b> and <strong></strong>. The <b></b> tag is a simple formatting tag that makes text bold, while the <strong></strong> tag indicates that the text is of strong importance, which also results in bold text.

For italic text formatting, the tags used are <i></i> and <em></em>. The <i></i> tag is used for simple italic formatting, while the <em></em> tag is used to emphasize the text, which typically renders as italic.

Can you explain how to apply underline and strikethrough effects in HTML?

To apply an underline effect in HTML, you use the <u></u> tag. This tag is straightforward and is used to simply underline the text for visual effect. For example:

<code class="html"><u>This text will be underlined.</u></code>

For a strikethrough effect, you can use either the <s></s> or <del></del> tags. The <s></s> tag indicates something that is no longer relevant or accurate, while the <del></del> tag specifies text that has been deleted from a document. Both result in a strikethrough effect. For example:

<code class="html"><s>This text will be strikethrough.</s>
<del>This text will also be strikethrough.</del></code>

Are there any differences in using these text formatting tags across various HTML versions?

In general, the use of basic text formatting tags like <b></b>, <i></i>, <u></u>, <s></s>, <strong></strong>, <em></em>, and <del></del> has remained consistent across HTML versions from HTML 4.01 to HTML5. However, there are some nuances and best practices to be aware of:

  • HTML 4.01 and Earlier: These versions primarily focus on the presentation of the text, where <b></b>, <i></i>, and <u></u> were commonly used for purely visual styling.
  • HTML5 and Semantic Tags: HTML5 introduced a greater emphasis on semantics. While the visual effects of tags like <b></b> and <i></i> remain the same, it is recommended to use <strong></strong> and <em></em> respectively, as these provide semantic meaning (importance and emphasis). The <u></u> tag is still used for underlining, but it's recommended to use CSS for styling instead due to its non-semantic nature. The <s></s> and <del></del> tags are preferred over purely presentational tags like <strike></strike> (which was deprecated in HTML 4.01 and removed from HTML5) because they offer semantic meaning (indicating something no longer relevant or deleted).

In practice, using these tags remains largely the same across HTML versions, but with HTML5, there is a shift toward using more semantic elements and less reliance on purely presentational tags, encouraging the use of CSS for styling when possible.

The above is the detailed content of How do you format text as bold, italic, underlined, or strikethrough in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn