HTML Tags Cheat Sheet
HTML tag cheat sheet: structure, text, form, media and semantic tags with names and notes for quick lookup while writing markup.
How It Works
HTML uses tags to organize text into a semantic document: headings, paragraphs, lists, links, tables. Semantic tags (header, main, section, article) align structure with meaning, helping accessibility and SEO.
Tags split into block-level (own line, e.g. div/p) and inline (within text, e.g. span/a); attributes (href, src, alt) carry extra info, with alt being essential for image accessibility. Modern HTML preaches "structure in tags, style in CSS, behavior in JS".
When to Use This Table
This table is for confirming the semantics, attributes and default behaviour of an HTML element. It lists common elements by structure, text, links, tables, forms and embedding, and notes content models (phrasing versus flow, whether interactive content is allowed) plus accessibility points. It is the reference when writing templates, reviewing code and auditing SEO.
When not to consult it: you are running a full accessibility audit or designing ARIA attributes. Element semantics are only part of accessibility; focus order, accessible names and roles, and live announcements all need systematic assessment.
Rule of thumb: prefer semantic elements over div plus a class. Semantic elements carry accessibility and SEO value on their own — engines understand h1–h6 hierarchy and article boundaries, while div provides nothing. Likewise the difference between button and a is behaviour, not styling: a navigates to a new view, button performs an action in place.
Mind combinations that look fine but are semantically wrong: an anchor wrapping a button (nested interactive content breaks keyboard and screen-reader behaviour), several h1 elements faking heading levels, tables used for layout (announced as data tables), and paragraphs wrapping block-level content.
Boundaries and Common Pitfalls
Interactive elements must not nest — an anchor around a button is simply wrong
An anchor wrapping a button is invalid per the HTML spec and behaves erratically: keyboard focus lands twice, Enter and Space activate different elements, and screen readers announce inconsistently. Pick one: for navigation use an anchor containing text or an icon; for an in-place action use a button containing text or an icon, and style it to look like a link.
Faking heading levels with styles harms both SEO and accessibility
Using h1 everywhere to control font size, or div plus font-size to imitate headings, destroys the document outline. Search engines rely on h1–h6 to understand structure, so a scrambled hierarchy weakens relevance judgements, and screen reader users navigate by heading, so a scrambled hierarchy makes content hard to reach. The rules: one h1 per page, descend without skipping levels (h2 followed by h4 is wrong), and solve sizing in CSS rather than by changing elements.
Tables used for layout get announced as data tables
When table is used for page layout, screen readers announce each cell as if it were data — a stream of meaningless "row 1, column 3". CSS Grid and Flexbox cover nearly all layout needs and should be preferred. If a table is unavoidable for layout, mark it role="presentation" (or role="none") so assistive technology ignores its semantics; and a real data table needs th elements with scope.
How This Relates to Neighbours
For character-level escaping and entity syntax, use the in-site HTML entities page; this one is about element semantics.
For the full value range and browser support of a specific attribute, consult MDN; this table covers common attributes only.
A full accessibility audit — contrast, focus order, ARIA, keyboard navigation — needs specialised tooling and manual testing, which is out of scope here.
If the goal is SEO, element semantics are only one part; structured data, internal links and metadata matter just as much.
Practical Snippet
Key points: (1) interactive elements must not nest — choose anchor or button, since nesting breaks keyboard and screen-reader behaviour; (2) one h1 per page with no skipped levels, and solve sizing in CSS, because heading structure drives both SEO and screen-reader navigation; (3) real data tables need th with scope, and a table used for layout needs role="presentation" (or none) — but prefer Grid/Flexbox; (4) every image needs alt, with an empty alt for decorative ones rather than omitting the attribute; (5) prefer semantic containers such as article, section, header and footer, since div with classes carries no semantics.
<!-- ① 跳转用 a,动作用的 button —— 二选一,不要嵌套 -->
<a href="/orders/42">查看订单</a>
<button type="button" @click="submit">提交</button>
<!-- ❌ <a href="/x"><button>去</button></a> -->
<!-- ② 一个页面一个 h1,层级不跳级 -->
<h1>订单详情</h1>
<h2>基本信息</h2>
<h3>收货地址</h3> <!-- ✅ h3 跟在 h2 后 -->
<!-- <h4>...</h4> 直接跟在 h2 后是错的 -->
<!-- 字号需求用 CSS,不要靠换标签 -->
<style>
h1 { font-size: 1.5rem; }
.minor-heading { font-size: .875rem; font-weight: 600; }
</style>
<!-- ③ 真数据表:th + scope + caption -->
<table>
<caption>近 7 日订单量</caption>
<thead>
<tr><th scope="col">日期</th><th scope="col">订单数</th></tr>
</thead>
<tbody>
<tr><th scope="row">10-01</th><td>128</td></tr>
</tbody>
</table>
<!-- ④ table 做布局时声明 presentation(现代浏览器用 none) -->
<table role="presentation">
<tr><td>侧栏</td><td>主内容</td></tr>
</table>
<!-- ✅ 更推荐:Grid / Flexbox -->
<div class="layout"><aside>侧栏</aside><main>主内容</main></div>
<style>.layout { display: grid; grid-template-columns: 240px 1fr; gap: 16px; }</style>
<!-- ⑤ 图片必须有 alt;装饰图用空 alt -->
<img src="chart.png" alt="近 7 日订单量折线图" width="640" height="320">
<img src="divider.svg" alt="" width="8" height="8"> <!-- 装饰性:空 alt -->
<!-- ⑥ 语义化容器优于 div 套类名 -->
<article>
<header><h2>标题</h2><time datetime="2024-06-01">6 月 1 日</time></header>
<section><h3>小节</h3><p>正文</p></section>
<footer>…</footer>
</article>
<!-- <div class="card"><div class="hd">… —— 全无语义价值 -->Practical Notes
- A <section> without an accessible name is not announcedOn a page with several <section> elements, the one lacking aria-label or a heading is skipped as a generic block. Give each section an aria-labelledby pointing at its h2 to make navigation meaningful.
- <div onclick> is not a substitute for <button>A div is not focusable, does not react to Enter or Space, and is not exposed as an operable control. Use native button or anchor elements for interaction and restyle them, or keyboard users are locked out entirely.
- Layout tables and data tables must be distinguishedUsing <table> for layout pollutes the table semantics read by screen readers. Data tables need a <caption> and scoped th cells so announcements make sense, and wide tables need an outer scrolling container or they stretch the whole page.
Data Sources
- WHATWG HTML Standard
- W3C WAI-ARIA 1.2
- MDN Web Docs (browser behaviour)
Codes, names and definitions above come from public specifications; we claim no originality over the specification data itself. The arrangement, Chinese annotations and practical notes on this page are written by us.
| Tag | Meaning |
|---|---|
| <a> | Anchor / hyperlink, jump or link |
| <img> | Embed image; src for URL, alt for alternative text |
| <div> | Generic block container, no semantics |
| <span> | Generic inline container, no semantics |
| <p> | Paragraph |
| <h1>-<h6> | Headings; h1 most important, decreasing |
| <ul> | Unordered list, with <li> |
| <ol> | Ordered list, with <li> |
| <li> | List item |
| <table> | Table, with thead/tbody/tr/th/td |
| <thead> | Table head |
| <tbody> | Table body |
| <tr> | Table row |
| <th> | Table header cell |
| <td> | Table data cell |
| <form> | Form container; action for submit URL |
| <input> | Input control; type decides kind |
| <button> | Button |
| <label> | Text label for a form control |
| <select> | Dropdown select |
| <textarea> | Multiline text input |
| <link> | Link external resource (e.g. stylesheet), usually in head |
| <meta> | Document metadata (charset, viewport, SEO) |
| <script> | Embed or reference JavaScript |
| <style> | Inline CSS |
| <header> | Header semantic section |
| <footer> | Footer semantic section |
| <nav> | Navigation semantic section |
| <section> | Independent section of the document |
| <article> | Self-contained distributable content (e.g. article) |
| <main> | Main page content (one per page) |
| <br> | Line break (void element) |
| <hr> | Thematic break (void element) |
| <strong> | Strong emphasis, semantically bold |
| <em> | Emphasis, semantically italic |
| <code> | Inline code snippet |
| <pre> | Preformatted text, preserves whitespace |
| <blockquote> | Block-level quotation |
| <iframe> | Embed another document/page |
| <video> | Embed video |
| <audio> | Embed audio |
| <canvas> | Draw graphics via script |
| <svg> | Scalable vector graphics |
Frequently Asked Questions
What is the difference between block and inline elements?
<div>, <p>, <h1>, <section> are block-level: they take a full line and accept width/height. <span>, <a>, <strong>, <code> are inline: they only occupy content width and do not force a line break. CSS controls layout today, but the semantics still matter.
When should I use <div> vs <section>?
Use <div> when there is no semantic content; use <section> when the content is a thematically independent part of the document (usually with a heading). Blindly wrapping everything in <div> hurts accessibility and SEO structure, but do not wrap every container in <section> either.
How do semantic tags help SEO?
<header>, <nav>, <main>, <article>, <footer> help search engines and assistive tech understand page structure, improving content extraction and accessibility scores compared to plain <div>.
What are void elements?
Elements with no closing tag, such as <img>, <br>, <hr>, <input>, <link>, <meta>. They cannot contain children and in HTML5 the trailing slash is optional.