On this page11 sections
Lecture 007: Formatting, Quotations & Comments
| Category | 2: Text & Styles |
| Lecture | 007 of 048 |
| Estimated video length | 12 min |
| Target | HTML5 · any modern browser |
| Level | Beginner |
Inside a paragraph you'll often want to stress a word, show a price that was cut, or mark a keyboard shortcut. HTML has a small element for each of these. Comments let you leave notes in your code that visitors never see.
Learning Objectives
- Mark important and emphasised text with
<strong>and<em> - Use
<mark>,<del>,<ins>,<small>,<sub>,<sup>,<code>and<kbd> - Quote text with
<blockquote>and<q> - Write HTML comments
1. Important and Emphasised Text
| Element | Meaning | Default look |
|---|---|---|
<strong> | Important | bold |
<em> | Stressed, as you'd say it aloud | italic |
Example
<p><strong>Warning:</strong> the oven is hot.</p>
<p>I said I wanted <em>tea</em>, not coffee.</p>You may also see <b> and <i>. They only change the look and carry no meaning. Prefer
<strong> and <em>, because screen readers can announce them.
2. Highlights, Changes and Small Print
Example
<p>Search results for <mark>biryani</mark>.</p>
<p>Price: <del>Rs 1,500</del> <ins>Rs 1,200</ins></p>
<p><small>Prices include 16% sales tax.</small></p><mark>: highlighted text, like a highlighter pen<del>/<ins>: text that was removed / added<small>: side comments and fine print
3. Subscript and Superscript
Example
<p>Water is H<sub>2</sub>O.</p>
<p>The area is 25 m<sup>2</sup>.</p>4. Code and Keyboard Keys
Example
<p>Use the <code><p></code> element for paragraphs.</p>
<p>Save the file with <kbd>Ctrl</kbd> + <kbd>S</kbd>.</p>< and > are entities: codes for < and >. Without them, the browser
would treat <p> as a real tag. Other useful ones are & (&) and © (©).
5. Quotations
<blockquote> holds a long quote as its own block. <q> holds a short quote inside a
sentence, and the browser adds the quote marks.
Example
<blockquote>
The best way to learn to code is to write code every day.
</blockquote>
<p>My teacher always says <q>practice beats talent</q>.</p>6. Comments
A comment starts with <!-- and ends with -->. The browser ignores it completely.
Example
<!-- Main title of the page -->
<h1>Our Menu</h1>
<!-- Desserts are coming next week
<h2>Desserts</h2>
-->
<p>Fresh food, every day.</p>Use comments to explain tricky parts, or to switch a piece of HTML off for a while. Comments are visible in View Page Source, so never put passwords in them.
Common Beginner Mistakes
1. Using <strong> just to make things bold. If the text isn't actually important, it's a
styling job for CSS.
2. Typing < in text. <p>Use <p> tags</p> breaks. Write <p>.
3. Unclosed comments. Forget --> and everything after it disappears from the page.
4. Secrets in comments. Anyone can read them with View Page Source.
Practice Questions
- Which element marks text as important:
<b>or<strong>? - Show an old price of Rs 900 crossed out and a new price of Rs 700.
- Write CO₂ using HTML.
- How do you display the text
<h1>on a page without the browser treating it as a tag? - Which element would you use for a famous quote that sits on its own?
- Write a comment that says "footer starts here".
Practice Answers
<strong>. It carries meaning;<b>only changes the look.<p><del>Rs 900</del> <ins>Rs 700</ins></p>CO<sub>2</sub>- Use entities:
<h1> <blockquote><!-- footer starts here -->
Key Takeaways
<strong>= important,<em>= stressed; prefer them over<b>and<i>.<mark>,<del>,<ins>,<small>,<sub>,<sup>,<code>,<kbd>each have one clear job.- Use entities such as
<and&for special characters. <!-- comments -->are invisible on the page but visible in the source.