萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> HTML5 教學

常用 HTML 標籤速查卡:結構、文字、圖片、表格、表單核心標籤一覽

文件骨架

<!DOCTYPE html>
<html lang="zh-Hant">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>頁面標題</title>
  <meta name="description" content="頁面描述">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header><nav>...</nav></header>
  <main>...</main>
  <footer>...</footer>
</body>
</html>

文字與語義 (高頻)

標籤用途範例
<h1>~<h6>標題層級<h1>主標題</h1>
<p>段落<p>內容...</p>
<strong>重要強調 (粗)<strong>關鍵</strong>
<em>語氣強調 (斜)<em>重點</em>
<span>行內無語義容器<span class="highlight">...</span>
<a href="">超連結<a href="/about">關於</a>
<ul><li>無序清單<ul><li>項</li></ul>
<ol><li>有序清單<ol><li>步驟</li></ol>
<blockquote>區塊引用<blockquote>引言</blockquote>
<code>行內代碼<code>const x=1</code>
<pre>預格式化 (保留縮進)<pre><code>...</code></pre>
<mark>高亮<mark>關鍵字</mark>
<time datetime="">機器可讀時間<time datetime="2024-01-15">1/15</time>

圖片與多媒體

<img src="photo.jpg" alt="風景照" width="800" height="600" loading="lazy">
<picture>
  <source srcset="photo.avif" type="image/avif">
  <source srcset="photo.webp" type="image/webp">
  <img src="photo.jpg" alt="風景">
</picture>
<video controls poster="cover.jpg">
  <source src="video.mp4" type="video/mp4">
</video>

表格核心

<table>
  <caption>產品價格表</caption>
  <thead><tr><th scope="col">產品</th><th scope="col">價格</th></tr></thead>
  <tbody>
    <tr><td>產品A</td><td>$100</td></tr>
  </tbody>
</table>

表單核心

<form action="/api/submit" method="post">
  <div>
    <label for="email">信箱</label>
    <input type="email" id="email" name="email" required placeholder="name@example.com">
  </div>
  <div>
    <label for="pwd">密碼</label>
    <input type="password" id="pwd" name="pwd" required minlength="8">
  </div>
  <button type="submit">送出</button>
</form>

其他實用標籤

  • <details><summary>點我展開</summary>隱藏內容</details> — 原生摺疊。
  • <dialog id="modal"><form method="dialog">...<button value="ok">確定</button></form></dialog> — 原生模態框,JS dialog.showModal()。
  • <template id="tpl"><div>重複內容</div></template> — JS cloneNode(true) 復用。

避坑提醒

  1. 勿用 <font>、<center>、<big>、<strike> 等棄用標籤。
  2. <img> 必填 alt,裝飾性圖片 alt=""。
  3. <label> 必須綁定 for=id 或包裹控件。
  4. 表單送出前驗證:HTML5 原生 required、pattern、min/max + JS checkValidity()。
copyright © 萬盛學電腦網 all rights reserved