萬盛學電腦網

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

HTML 標籤與屬性速查手冊:從區塊結構到表單元素的完整語法索引

文件結構標籤

標籤描述關鍵屬性
<!DOCTYPE html>HTML5 文件類型宣告—
<html>根元素lang
<head>元資料容器—
<title>文件標題—
<meta>元資料charset, name, content, http-equiv
<link>外部資源連結rel, href, type, media
<style>內部樣式type, media
<script>腳本src, async, defer, type
<body>文件主體onload, onunload (事件屬性)

區塊語義標籤 (HTML5)

標籤語義典型用途
<header>頁首/區塊標題群Logo、導航、搜尋
<nav>主要導航選單、麵包屑
<main>主要內容 (唯一)文章、產品詳情
<article>獨立完整內容部落格文、新聞、評論
<section>主題性區塊章節、標籤頁面板
<aside>側邊/附加資訊側邊欄、廣告、相關連結
<footer>頁尾/區塊尾部版權、聯絡、站點地圖
<div>無語義通用容器樣式/JS 掛鉤、最後手段

文字層級語義標籤

標籤語義預設樣式
<a>超連結底線、藍色
<strong>重要性強調粗體
<em>語氣強調斜體
<b>視覺粗體 (無語義)粗體
<i>視覺斜體/慣用語/專有名詞斜體
<u>標註 (錯字、中文專有名號)底線
<mark>高亮標記黃底
<small>細節/免責聲明小字
<del>/<ins>刪除/插入刪除線/底線
<sub>/<sup>下標/上標縮小上下移
<code>程式碼片段等寬字體
<kbd>鍵盤輸入等寬字體
<samp>程式輸出等寬字體
<var>變數斜體
<cite>著作標題斜體
<q>短引用 (自動加引號)引號
<abbr>縮寫 (配合 title)底虛線
<dfn>定義術語斜體
<time>日期時間 (datetime)—
<data>機器可讀數值 (value)—
<ruby>/<rt>/<rp>注音/拼音—
<bdi>/<bdo>雙向文字隔離/覆寫—
<span>無語義行內容器—
<br>換行—
<wbr>建議斷詞機會—

清單與定義

標籤用途
<ul>無序清單
<ol>有序清單 (reversed, start, type)
<li>清單項目 (value)
<dl>定義清單
<dt>定義術語
<dd>定義描述

圖片與多媒體

標籤關鍵屬性
<img>src, alt (必填), width, height, loading, decoding, srcset, sizes
<picture>容器,含多個 <source> + 1 個 <img>
<source>srcset, media, type
<video>src, controls, autoplay, loop, muted, poster, preload
<audio>src, controls, autoplay, loop, muted, preload
<track>kind, src, srclang, label, default
<canvas>width, height (JS 繪圖)
<svg>向量圖形 (內嵌 XML)
<map>/<area>圖像地圖 (shape, coords, href, alt)

表單元素

標籤關鍵屬性
<form>action, method (GET/POST), enctype, novalidate, target
<input>type (text/email/password/number/date/checkbox/radio/file/hidden/submit/button/color/range...), name, value, placeholder, required, disabled, readonly, autocomplete, pattern, min, max, step, list
<textarea>name, rows, cols, placeholder, required, maxlength, wrap
<select>name, multiple, size, required, disabled
<option>value, selected, disabled, label
<optgroup>label, disabled
<button>type (submit/reset/button), name, value, disabled, formaction, formmethod
<label>for (對應 input id), 內容模型包裹 input
<fieldset>/<legend>群組相關欄位
<datalist>id (供 input list 參考)
<output>for (關聯輸入 id), name
<meter>value, min, max, low, high, optimum
<progress>value, max

表格標籤

標籤關鍵屬性
<table>border, cellpadding, cellspacing (建議改 CSS)
<caption>表格標題
<thead>/<tbody>/<tfoot>表格區段
<tr>列
<th>表頭 (scope="col|row|colgroup|rowgroup", abbr)
<td>資料 (colspan, rowspan, headers)
<colgroup>/<col>欄群組/欄屬性 (span, width)

互動與腳本

標籤用途
<details>/<summary>原生摺疊面板 (無需 JS)
<dialog>原生對話框 (showModal())
<slot>Web Components 插槽
<template>HTML 模板 (JS 實例化)
<script>JavaScript (module/defer/async)
<noscript>無 JS 環境替代內容

已棄用/避免使用的標籤與屬性

  • <font>, <center>, <strike>, <big>, <tt>, <frame>, <frameset>, <noframes>, <acronym>, <applet>, <isindex>, <dir>, <basefont>。
  • 屬性:align, bgcolor, border (於 table), width/height (非 img/video/canvas), scrolling, valign, cellpadding, cellspacing 等表現屬性。
copyright © 萬盛學電腦網 all rights reserved