Document Structure
<!DOCTYPE>: Declares the document type and HTML version<html>: Root element of an HTML page<head>: Contains metadata and document info<title>: Specifies the title of the document<body>: Contains the visible page content
Semantic Tags (HTML5)
1. Document Structure
-
Tag
Description
Example
<header>Introductory content for a section or page (e.g., logo, navigation).
<header><h1>Website Title</h1></header><footer>Footer content for a section or page (e.g., copyright, contact info).
<footer>© 2023 My Site</footer><nav>Navigation links (menus, tables of contents).
<nav><a href="/home">Home</a></nav><main>Primary content of the document (only one per page).
<main><article>...</article></main>
2. Content Sections
Tag
Description
Example
<article>Self-contained content (e.g., blog post, news article).
<article><h2>Blog Post Title</h2><p>Content...</p></article><section>Thematic grouping of content (e.g., chapters, tabs).
<section><h2>Chapter 1</h2><p>Text...</p></section><aside>Content indirectly related to the main content (e.g., sidebars, ads).
<aside><h3>Related Links</h3></aside>
3. Media & Figures
Tag
Description
Example
<figure>Self-contained media (e.g., images, diagrams, code snippets).
<figure><img src="image.jpg"><figcaption>Caption</figcaption></figure><figcaption>Caption for a
<figure>.See above.
4. Text Semantics
Tag
Description
Example
<time>Represents a date/time (machine-readable).
<time datetime="2023-10-05">October 5, 2023</time><mark>Highlighted text (e.g., search results).
<mark>Highlighted text</mark><small>Fine print (disclaimers, copyrights).
<small>© 2023 My Site</small><address>Contact information for the page/section author.
<address>Contact: <a href="mailto:me@example.com">Email</a></address>
5. Interactive Elements
Tag
Description
Example
<details>Collapsible widget with toggleable content.
<details><summary>Click Me</summary><p>Hidden content</p></details><summary>Heading for a
<details>element.See above.
<dialog>Popup/modal dialog box.
<dialog open><p>Hello! I'm a dialog.</p></dialog>
6. Data Representation
Tag
Description
Example
<progress>Progress indicator (e.g., file upload).
<progress value="70" max="100">70%</progress><meter>Scalar measurement within a range (e.g., disk usage).
<meter value="3" min="0" max="10">3/10</meter>
7. Text Annotations
Tag
Description
Example
<ruby>Ruby annotations (for East Asian typography).
<ruby>漢<rt>Kan</rt></ruby><rt>Pronunciation/text for
<ruby>annotations.See above.
<rp>Fallback parentheses for browsers without ruby support.
<ruby>漢<rp>(</rp><rt>Kan</rt><rp>)</rp></ruby>
8. Bidirectional Text
Tag
Description
Example
<bdi>Isolates text direction (e.g., user-generated content in mixed languages).
<bdi>إيان</bdi> wrote this.<bdo>Overrides text direction (use
dir="rtl"ordir="ltr").<bdo dir="rtl">This text is reversed.</bdo>
9. Word Breaks
Tag
Description
Example
<wbr>Suggests a word break opportunity in long words/URLs.
https://example.com/<wbr>very-long-path
Best Practices
-
Use semantic tags instead of generic
<div>/<span>where possible. -
Avoid nesting multiple
<article>/<section>tags without headings. -
Use one
<main>per page for primary content. -
Combine with ARIA roles for enhanced accessibility.
Deprecated Tags to Avoid
-
<center>,<font>,<big>,<strike>(use CSS or semantic tags instead).
By using these tags, you improve accessibility (screen readers), SEO (search engines), and code readability. Let me know if you need examples for specific use cases! 🚀
-
Metadata
<meta>: Metadata about the document (e.g., charset, viewport)<link>: Links to external resources (e.g., CSS)<style>: Embedded CSS styles<script>: Client-side JavaScript code<base>: Base URL for relative URLs
Text Formatting
<h1>to<h6>: Headings<p>: Paragraph<br>: Line break<hr>: Thematic break (horizontal line)<pre>: Preformatted text<blockquote>: Long quotation<q>: Short inline quotation<code>: Code snippet<em>: Emphasized text<strong>: Important text<i>: Italicized text (e.g., technical terms)<b>: Bold text (stylistic)<u>: Underlined text<sub>: Subscript text<sup>: Superscript text<small>: Smaller text (e.g., disclaimers)<span>: Inline container for styling
Lists
<ul>: Unordered list<ol>: Ordered list<li>: List item<dl>: Description list<dt>: Term in a description list<dd>: Description of a term
Links & Media
<a>: Hyperlink<img>: Embeds an image<audio>: Embeds audio<video>: Embeds video<source>: Media source for<audio>/<video><track>: Text tracks for media (e.g., subtitles)<embed>: Embeds external content (e.g., plugins)<object>: Embeds external resource<iframe>: Embeds another HTML page
Tables
<table>: Defines a table<tr>: Table row<th>: Table header cell<td>: Table data cell<thead>: Groups header content in a table<tbody>: Groups body content in a table<tfoot>: Groups footer content in a table<caption>: Table caption<colgroup>: Groups table columns<col>: Specifies column properties
Forms
<form>: Interactive form<input>: Input field (text, checkbox, radio, etc.)<textarea>: Multi-line text input<button>: Clickable button<select>: Drop-down list<option>: Option in a<select><optgroup>: Groups related<option>s<label>: Label for form elements<fieldset>: Groups related form elements<legend>: Caption for<fieldset><datalist>: Predefined options for<input><output>: Result of a calculation<progress>: Progress bar<meter>: Scalar measurement within a range
Interactive Elements
<menu>: Context menu (rarely used)<template>: Client-side content template<slot>: Placeholder in a web component<canvas>: Draw graphics via JavaScript
Other Tags
<div>: Generic block-level container<span>: Generic inline container<abbr>: Abbreviation or acronym<address>: Contact information<cite>: Title of a work (e.g., book)<data>: Machine-readable data<del>: Deleted text<ins>: Inserted text<kbd>: Keyboard input<samp>: Sample output<var>: Variable<wbr>: Word break opportunity<bdi>: Bi-directional isolation<bdo>: Bi-directional override<ruby>: Ruby annotations (for East Asian typography)<rt>: Ruby text<rp>: Ruby parentheses
Deprecated Tags (Avoid in HTML5)
<acronym>,<applet>,<basefont>,<big>,<center>,<dir>,<font>,<frame>,<frameset>,<noframes>,<strike>,<tt>
