head 區域位於 HTML 文件的 <head> 與 </head> 之間,主要用來提供瀏覽器與搜尋引擎所需的頁面資訊。以下整理首頁 head 區常見的撰寫項目。
例如:<!-- The site is designed by Example Inc. -->
簡體中文:<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
繁體中文:<meta http-equiv="Content-Type" content="text/html; charset=BIG5" />
通用寫法:<meta charset="utf-8" />
<meta name="author" content="webmaster@example.com" />
<meta name="description" content="網站內容簡介" />
<meta name="keywords" content="關鍵字1,關鍵字2,關鍵字3" />
<link href="style/style.css" rel="stylesheet" type="text/css" />
<title>網站名稱或頁面標題</title>
<meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Window-target" content="_top" />
<meta http-equiv="Refresh" content="5;URL=https://example.com" />
<meta name="robots" content="index,follow" />
<link rel="shortcut icon" href="favicon.ico" />
建議將 JavaScript 放在外部檔案中,再透過 script 標籤載入:
<script src="script/main.js" type="text/javascript"></script>
head 區雖然不是使用者直接看到的內容,卻會影響瀏覽器解析、搜尋引擎理解與頁面效能。養成良好撰寫習慣,能讓網站更穩定、更易維護。