Headings and paragraphs separate large pieces of content. Within a paragraph, smaller elements can identify an important warning, spoken emphasis or code. Ask why the words are special before choosing a tag.
Importance and emphasis
strong identifies importance, seriousness or urgency. em indicates stress emphasis. Browsers usually render them in bold and italics respectively, but their meanings are the main distinction:
<p><strong>Register in advance.</strong> Please attend <em>in person</em>.</p>The first sentence is an important instruction; “in person” is the emphasis. b can draw attention without extra importance, such as a keyword. i can identify text of a different nature, such as a technical term. They are not exact semantic substitutes for strong and em. Pure decoration belongs in CSS.
Highlights and code
mark highlights text relevant in the current context, such as a search match. code identifies computer code, commonly shown in a monospace font:
<p>Search result: weekend <mark>reading</mark> club.</p>
<p>A paragraph uses <code><p></code>.</p>code does not disable HTML parsing: escape brackets with character references. For multiple lines with preserved whitespace, nest code inside pre, meaning preformatted text:
<pre><code><h1>My page</h1>
<p>My introduction.</p></code></pre>Unlike a normal paragraph, pre preserves spaces and line breaks. Extra indentation may therefore become visible. In the Lab, compare an event reminder with a code notebook. Edit the strong boundaries and the line breaks in pre. Default appearance helps you observe, but meaning should guide your element choice.
Page experiment: Text formatting and meaning
Compare the examples, then change one part of the HTML using the observation prompt. Compare the source with the real rendered page.
strong marks importance, em adds stress, and mark highlights contextual relevance.
The preview uses native browser headings, paragraphs and form controls. Switching examples replaces your edits; Reset lab restores the initial state. Follow in-page links, type and select options. This practice preview does not send form data or run scripts. To try locally, save the complete code as index.html and open it in a browser.
KNOWLEDGE QUIZ
Build it yourself: Text formatting and meaning
Create index.html, write a complete page using the requirements below, then save and open it in a browser. Interact with the page to check it. The reference is one possible implementation; wording may differ.
- Write a notice with “Bring your ticket” in strong and “on time” in em.
- Use pre and code to display two HTML source lines with visible bracket characters.