Sub topic 2
Section versus article
Assume you know HTML tags, attributes, nesting, and the basic role of CSS. Semantic HTML uses elements according to their meaning, not their default appearance.
Section and article
Use section for a thematic group within a page. It normally has a heading. Use article for content that could stand alone or be reused, such as a news story, review, or forum post.
<main>
<h1>Web development</h1>
<section>
<h2>Latest articles</h2>
<article>
<h3>Choosing semantic elements</h3>
<p>An article can make sense when separated from this page.</p>
</article>
</section>
</main>A section organizes related content. An article identifies an independent item. Neither element exists merely to create a visual box.
Lists, figures, quotes, and addresses
Use ul for an unordered list and ol when order matters. Use figure with figcaption for a self-contained illustration, example, or data display. Use blockquote for an extended quotation. Use address for contact information about the nearest page or article author.
Meaning inside text
Choose inline elements by meaning:
strongmarks importance.emmarks emphasis or stress.codemarks a code fragment.abbrmarks an abbreviation, often with atitleattribute.
CSS can change how these elements look without changing their meaning.
Machine-readable values
Use time when a date or duration is part of the content. Its datetime attribute gives software a consistent value. Use data when visible text represents a value that software can identify.
<p>Updated <time datetime="2026-11-30">30 November 2026</time>.</p>
<p>Price: <data value="29.99">$29.99</data></p>Tables for tabular data
Use tables for relationships between rows and columns, not for page layout. Give the table a caption, and use th with scope so assistive technology can associate headers with cells.
| Element | Purpose |
|---|---|
| `caption` | Names the table |
| `th scope="col"` | Labels a column |
| `th scope="row"` | Labels a row |
Forms: labels, fieldsets, and legends
Every form control needs an associated label. Group related controls with fieldset and name the group with legend.
<form>
<fieldset>
<legend>Contact details</legend>
<label for="email">Email address</label>
<input id="email" name="email" type="email" required>
</fieldset>
<button type="submit">Send</button>
</form>Exercise
Should a collection of independent blog posts use one section or several articles?
Show answer
Use a section for the collection and one article for each independent post.