萬盛學電腦網

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

HTML 頁面核心標籤速查:結構、語義、常用屬性一覽

文檔骨架

<!DOCTYPE html>
<html lang="zh-Hant">
  <head>
    <meta charset="UTF-8">
    <title>頁面標題</title>
    <meta name="keywords" content="關鍵詞">
    <meta name="description" content="頁面描述">
    <link rel="stylesheet" href="style.css">
    <script src="app.js" defer></script>
  </head>
  <body>
    <!-- 可見內容 -->
  </body>
</html>

核心標籤分類速查

類別標籤語義/用途關鍵屬性
文檔結構<html>根元素lang
<head>元數據容器—
<body>可見內容容器—
元數據<title>頁面標題(瀏覽器標籤、SEO 關鍵)—
<meta>字符集、視口、SEO、HTTP 模擬charset, name, content, http-equiv
樣式/腳本<link>外部資源(CSS、favicon、preload)rel, href, as
<script>內聯/外部 JavaScriptsrc, defer, async, type=module
文本語義<h1>-<h6>標題層級—
<p>段落—
<strong>/<em>重要/強調—
<a>超鏈接href, target, rel
<span>行內無語義容器—
<br>換行—
<mark>高亮標記—
列表<ul>/<ol>/<li>無序/有序列表type, start, reversed
<dl>/<dt>/<dd>描述列表—
表格<table>/<thead>/<tbody>/<tr>/<th>/<td>表格數據colspan, rowspan, scope
表單<form>/<input>/<textarea>/<select>/<button>/<label>用戶輸入type, name, value, required, disabled
媒體<img>圖片src, alt, width, height, loading
<video>/<audio>視頻/音頻src, controls, preload, loop
區塊語義(HTML5)<header>/<footer>/<nav>/<main>/<article>/<section>/<aside>頁面區域語義化—
其他<div>通用區塊容器(無語義)—
<hr>主題分隔—
<iframe>內嵌瀏覽上下文src, sandbox, allow

核心原則

  1. 標籤必須是規範定義的,不可自造標籤(除 Web Components)。
  2. 語義優於表現:用 `` 而非 ``、用 `
    ` 而非 `
    `。
  3. 屬性值加引號,布爾屬性可簡寫(``)。
  4. 嵌套規則:區塊級可包含行內,行內不可包區塊級(`` 除外)。

結語

熟練掌握核心標籤與屬性,是編寫語義化、無障礙、SEO 友好 HTML 的基石。

copyright © 萬盛學電腦網 all rights reserved