HTML Text Formatting
HTML provides a series of tags for formatting text, giving them special styles or semantic meanings. These tags can be divided into two categories: physical tags (focused on visual presentation) and logical tags (focused on semantic meaning).
In modern web development, we recommend using logical tags with semantic meaning and leaving pure style control to CSS.
Physical Tags vs. Logical Tags
Best Practice: Prefer logical tags like <strong> and <em> because they provide both visual styling and semantic information, which is better for SEO and accessibility.
Common Formatting Tag Examples
Bold and Strong
Italic and Emphasis
Marked or Highlighted Text
Use the <mark> tag to highlight text, like marking with a highlighter.
Small Text
The <small> tag is used to define smaller text, often used for copyright information or footnotes.
Deleted and Inserted Text
<del> and <ins> are often used together to show editing and revision history in documents.
Browsers typically add a strikethrough to <del> and an underline to <ins>.
Subscript and Superscript
<sub>(Subscript) is used to define subscript text, commonly used in chemical formulas or mathematical expressions.<sup>(Superscript) is used to define superscript text, commonly used in footnotes or mathematical exponents.