HTML 標籤綜合參考手冊(經典分類版)
本文按功能分類彙總 HTML 標籤用法,涵蓋文本排版、圖片處理、表格構建、框架佈局、多媒體嵌入五大核心模塊,適合初學者系統學習與開發者快速查閱。
一、文本排版標籤
| 分類 | 標籤/屬性 | 說明 |
| 標題 | <h1>-<h6> | h1 最大,h6 最小 |
align="left|center|right" | 對齊方式(棄用) |
現代 CSS: text-align |
| 語義:h1 頁面主標題,層級嚴禁跳級 |
| SEO:h1 包含核心關鍵詞,每頁僅一個 |
| 無障礙:屏幕閱讀器按 H 鍵導航 |
| 字體樣式 | <font> size(1-7), face, color | HTML4 棄用,改用 CSS |
<small>, <big> | 小/大字體 |
<b>, <strong> | 粗體/重要 |
<i>, <em> | 斜體/強調 |
<tt> | 等寬字體 |
<u>, <s>, <strike> | 下劃線/刪除線 |
<sub>, <sup> | 下標/上標 |
<blink> | 閃爍(極不推薦,已移除) |
| 段落與換行 | <br> | 單行換行 |
<p> | 段落(雙換行) |
<p align="left|center|right"> | 對齊(棄用) |
<hr> | 分隔線:size, width, align, color, noshade |
| 現代:CSS margin, border-bottom |
| 對齊與預格式 | <center> | 居中容器(棄用) |
<pre> | 保留空白換行 |
<pre width="?"> | 寬度(字符數) |
| Body 屬性(棄用) | bgcolor | 背景色 |
| background | 背景圖 |
| bgproperties="fixed" | 固定背景 |
| text | 文本色 |
| link | 未訪問鏈接色 |
| vlink | 已訪問鏈接色 |
| alink | 激活鏈接色 |
| 現代:CSS body {background, color} |
| 跑馬燈(非標準) | <marquee> | scrollAmount 速度, direction 方向 |
| 現代:CSS @keyframes 動畫替代 |
| 無障礙:運動敏感用戶會致不適 |
二、圖片標籤
| 屬性/標籤 | 說明 |
<img src="url"> | 插入圖片 |
border | 邊框寬度 |
width, height | 尺寸(必設,防 CLS) |
hspace, vspace | 水平/垂直留白 |
alt="描述" | 替代文本(必填,SEO/無障礙) |
lowsrc | 低解析度預載圖 |
| 圖像映射 |
<img usemap="#name"> | 關聯 map |
<map name="name"> | 定義熱區 |
<area shape="rect" coords="x1,y1,x2,y2" href="..."> | 矩形熱區 |
<area shape="circle" coords="cx,cy,r" href="..."> | 圓形熱區 |
<area shape="poly" coords="x1,y1,x2,y2,..." href="..."> | 多邊形熱區 |
三、表格相關標籤
| 標籤 | 關鍵屬性 | 說明 |
<caption> | align="top|bottom" | 表格標題 |
<tr> | align, valign | 行定義 |
<td> | align, valign, width, rowspan, colspan, nowrap, bgcolor | 數據單元格(左對齊) |
<th> | align, valign, width, rowspan, colspan, nowrap, bgcolor | 表頭單元格(居中加粗) |
四、表格主要屬性詳解
| 元素 | 屬性 | 說明 |
<table> | align | center/left/right 表格對齊 |
| background | 背景圖片 URL |
| bgcolor | 背景顏色 |
| border | 邊框寬度 |
| bordercolor | 邊框顏色 |
| cellpadding | 單元格內邊距 |
| cellspacing | 單元格間距 |
| height | 表格高度 |
| width | 表格寬度(像素/%) |
| 現代:CSS border-collapse, padding, width |
<tr> | align, background, bgcolor | 行級樣式 |
| 現代:CSS tr:nth-child() 選擇器 |
| 語義:thead/tbody/tfoot 自動分組 |
| 無障礙:scope="col|row" 關聯表頭 |
<td>/<th> | colspan, rowspan | 跨列/跨行合併 |
| width (%/px) | 單元格寬度 |
| nowrap | 不換行(CSS white-space:nowrap) |
| bgcolor | 背景色 |
| 現代:CSS td/th 選擇器控制 |
五、框架標籤(HTML5 棄用 frameset/frame,保留 iframe)
| 標籤 | 屬性 | 說明 |
<frameset> | rows, cols (分割比例) | 替代 body,定義框架集 |
<frame> | src, name, marginwidth, marginheight, scrolling, noresize | 單個框架 |
<noframes> | - | 降級內容 |
<iframe> | src, width, height, sandbox, allow, loading, referrerpolicy | 內聯框架(現代保留) |
六、多媒體嵌入(音樂/視頻)
⚠️ 歷史方案(已淘汰): <embed>, <bgsound>, RealPlayer/WMP 插件
現代標準方案(HTML5)
<!-- 音頻 -->
<audio controls preload="metadata">
<source src="music.mp3" type="audio/mpeg">
<source src="music.ogg" type="audio/ogg">
您的瀏覽器不支持音頻播放
</audio>
<!-- 視頻 -->
<video controls width="640" height="360" poster="cover.jpg">
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
<track kind="subtitles" src="sub.vtt" srclang="zh" label="中文">
您的瀏覽器不支持視頻播放
</video>
常用屬性
| 屬性 | 音頻 | 視頻 | 說明 |
| controls | ✓ | ✓ | 顯示播放控件 |
| autoplay | ✓ | ✓ | 自動播放(需 muted) |
| loop | ✓ | ✓ | 循環播放 |
| muted | ✓ | ✓ | 靜音 |
| preload | ✓ | ✓ | none/metadata/auto |
| poster | - | ✓ | 封面圖 |
| playsinline | - | ✓ | iOS 內聯播放 |
| crossorigin | ✓ | ✓ | 跨域設置 |
七、綜合應用示例:音樂播放頁面
<div style="text-align:center; background:url(bg.jpg); padding:40px;">
<h2 style="color:#fff; font-family:'華文彩雲';">歌曲名稱</h2>
<img src="cover.jpg" alt="專輯封面" style="max-width:100%;">
<p style="color:#fff;">歌曲介紹文字</p>
<audio controls autoplay loop style="width:250px;">
<source src="music.mp3" type="audio/mpeg">
</audio>
</div>
本手冊涵蓋從傳統到現代的 HTML 標籤用法,建議新項目遵循 HTML5 標準,使用語義化標籤、CSS 分離表現、無障礙屬性,構建高質量 Web 體驗。