Inline Text Formatting π¨ΒΆ
Prerequisites: Structural Text Elements
Mentor's Note: Think of inline text formatting tags like the tools inside your school pencil case. You have a bold marker to highlight key terms (
<strong>), a highlighter pen (<mark>), a red pen to cross things out (<del>), and small notations (<sub>,<sup>). Let's learn how to apply these styles in code! βοΈπ Educational Content: This guide covers inline-level formatting elements used to style text segments.
What You'll Learn
By the end of this tutorial, you'll know:
- The difference between semantic (<strong>, <em>) and physical styling (<b>, <i>)
- How to highlight text using <mark>
- How to write math and science formulas using <sub> and <sup>
- How to mark text modifications using <del> and <ins>
π The Scenario: The Studied Notes πΒΆ
Mental Model: Highlighting a notebook. Imagine you are reviewing your notes for the board exam:
- The Core Term (
<strong>): You write it extra thick with a black pen because it has high importance. - The Book Title (
<em>): You write it in slanted letters (italics) because it's a title. - The Formula (
<sub>and<sup>): You write the "2" slightly lower in \(H_2O\) and slightly higher in \(x^2\). - The Correction (
<del>and<ins>): You draw a line through a wrong answer and write the corrected word next to it. β
π Inline Formatting ElementsΒΆ
HTML provides two types of formatting tags: Semantic (which tell search engines and screen readers that the text is important) and Physical (which only change visual appearance).
1. Importance: <strong> vs <b>ΒΆ
<strong>(Semantic): Tells the browser that the text has strong importance. Screen readers read it with emphasis. Renders as bold.<b>(Physical): Simply styles the text as bold without adding any semantic importance.
2. Emphasis: <em> vs <i>ΒΆ
<em>(Semantic): Tells the browser the text has emphasis (e.g., changes the meaning of a sentence depending on which word is emphasized). Renders as italics.<i>(Physical): Simply styles the text as italics without semantic meaning (e.g., technical terms, thoughts, book titles).
3. Subscript & SuperscriptΒΆ
<sub>(Subscript): Lowers the text baseline (useful for chemical formulas).<sup>(Superscript): Raises the text baseline (useful for math exponents and ordinals).
4. Highlighting & ModificationsΒΆ
<mark>: Highlights text (usually yellow background).<del>: Deleted text (strikethrough).<ins>: Inserted text (underlined).<small>: Reduces font size by one level.
π¨ Visual Logic: Formatting PunctuationΒΆ
Remember: formatting tags are inline. They do not force line breaks:
Renders inline as:The code is bold and italic.
π§ͺ Interactive ElementsΒΆ
Try It YourselfΒΆ
Hands-on Exercise
Task: Write the HTML code to display this sentence with the exact same styles: "Einstein's famous equation is E = mcΒ² where c is the speed of light."
Quick QuizΒΆ
Quick Quiz
Which tag is used to display chemical formulas like COβ?
- [ ] <sup>
- [x] <sub>
- [ ] <formula>
- [ ] <down>
Explanation: <sub> stands for subscript, which places the enclosed text slightly below the baseline (e.g., CO<sub>2</sub>). <sup> is superscript (above the baseline).
π Best Practices & Common MistakesΒΆ
β Best PracticesΒΆ
- Prefer semantic tags (
strong,em): Use them instead ofbandito make your site accessible and SEO friendly. - Nest formatting tags properly: Make sure they close in the correct order:
<strong><em>Text</em></strong>(correct).
β Common Mistakes β οΈΒΆ
- Nesting overlapping tags:
- Incorrect:
<strong><em>Text</strong></em>(overlapping). - Using
<u>for emphasis: The<u>tag (underline) can be confused with hyperlinks. Avoid using it unless indicating spelling errors.
π‘ Board Focus & Exam Tips πΒΆ
Common Board Questions (GSEB/CBSE/ICSE)ΒΆ
- Q: What is the difference between
<strong>and<b>tags in HTML? - Answer:
<strong>is a semantic tag that tells screen readers and search engines that the text is of high importance.<b>is a physical text style tag that simply bolds the text visually without indicating any semantic importance.- Q: Write the HTML tags used for subscript and superscript.
- Answer:
<sub>is used for subscripts, and<sup>is used for superscripts.
π Related ConceptsΒΆ
Next StepsΒΆ
- Block vs Inline Display Modes β Learn why these formatting elements wrap inside paragraphs instead of breaking onto new lines.
- HTML Links β Learn how inline anchors use formatting tags.