萬盛學電腦網

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

HTML 區塊完整指南:title、link、style、base、script、meta 詳細用法

<head> 是網頁的大腦,包含文檔元數據、資源引入、行為配置。掌握每個標籤的正確用法,是構建標準、高效、SEO 友好頁面的基礎。

核心標籤速查表

標籤用途關鍵屬性
<title>文檔標題,唯一,顯示於瀏覽器標籤、書籤、搜尋結果無
<link>外部資源關聯,最常用於樣式表rel="stylesheet", href, type, media
<style>內部樣式表type="text/css", media
<base>指定頁面所有相對連結的基準 URL 與目標href, target
<script>嵌入或引入 JavaScriptsrc, type, async, defer, charset
<meta>元數據,模擬 HTTP 響應頭或提供文檔資訊name, http-equiv, content, charset

<meta> 兩大屬性體系詳解

1. name 屬性:面向搜尋引擎與瀏覽器

name 值用途範例
keywords頁面關鍵字(現搜尋引擎權重極低)<meta name="keywords" content="HTML, CSS, 教學">
description頁面描述,搜尋結果摘要來源<meta name="description" content="HTML head 完整指南...">
author作者資訊<meta name="author" content="張三">
generator生成工具<meta name="generator" content="VS Code">
robots爬蟲指令:index/noindex, follow/nofollow, all/none<meta name="robots" content="index,follow">
viewport行動裝置視口設定(響應式必備)<meta name="viewport" content="width=device-width, initial-scale=1">

2. http-equiv 屬性:模擬 HTTP 響應頭

http-equiv 值用途範例
Content-Type指定字符編碼(HTML5 建議用 <meta charset="utf-8">)<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Content-Language文檔語言<meta http-equiv="Content-Language" content="zh-TW">
Refresh定時重導向<meta http-equiv="Refresh" content="5; url=https://example.com">
Expires緩存過期時間(GMT 格式)<meta http-equiv="Expires" content="Mon, 12 May 2025 00:20:00 GMT">
Pragma禁用緩存(HTTP/1.0 相容)<meta http-equiv="Pragma" content="no-cache">
Set-Cookie設定 Cookie(建議用 HTTP 標頭)<meta http-equiv="Set-Cookie" content="name=value; expires=...">
X-UA-Compatible指定 IE 渲染模式<meta http-equiv="X-UA-Compatible" content="IE=edge">
Page-Enter/Exit頁面進出轉場效果(IE 專屬,已廢棄)<meta http-equiv="Page-Enter" content="revealTrans(duration=1,transition=12)">

現代最佳實踐精簡版

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="頁面精準描述,150 字內">
  <title>頁面標題 | 網站名稱</title>
  <link rel="stylesheet" href="styles.css">
  <link rel="icon" href="favicon.ico">
  <script src="app.js" defer></script>
</head>

原則:最小化 head、優先外部資源、善用 defer/async、移除廢棄 http-equiv(轉用真實 HTTP 標頭)。

copyright © 萬盛學電腦網 all rights reserved