Favicon(收藏夾圖示)是網站品牌識別的關鍵細節。從傳統 .ico 到現代多尺寸 PNG、SVG、Apple Touch Icon、Web App Manifest,本文整理跨瀏覽器、跨裝置的完整設定指南。
favicon.ico(16×16、32×32、48×48 多解析度內含)放在網站根目錄。/favicon.ico,無需任何標記。<head>
<!-- 標準 Favicon -->
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16.png" />
<!-- Apple Touch Icon (iOS Safari 主畫面捷徑) -->
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<!-- Android Chrome / PWA -->
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#ffffff" />
</head>
// manifest.json
{
"name": "我的網站",
"short_name": "網站",
"icons": [
{ "src": "/icon-72.png", "sizes": "72x72", "type": "image/png" },
{ "src": "/icon-96.png", "sizes": "96x96", "type": "image/png" },
{ "src": "/icon-128.png", "sizes": "128x128", "type": "image/png" },
{ "src": "/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any maskable" },
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any maskable" }
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone",
"start_url": "/"
}
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<!-- 深色模式適配 -->
<link rel="icon" type="image/svg+xml" media="(prefers-color-scheme: dark)" href="/favicon-dark.svg" />
favicon.svg 範例:
<svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 100 100">
<circle cx="50" cy="50" r="45" fill="currentColor"/>
<text x="50" y="62" text-anchor="middle" font-size="60" fill="white">A</text>
</svg>
| 用途 | 尺寸 | 格式 | rel 值 |
|---|---|---|---|
| 瀏覽器分頁/書籤 | 16×16, 32×32 | ICO / PNG | icon |
| Windows 磚狀 | 48×48, 144×144 | PNG | icon / msapplication-TileImage |
| iOS 主畫面 | 180×180 | PNG | apple-touch-icon |
| Android Chrome / PWA | 192×192, 512×512 | PNG | manifest icons |
| 現代瀏覽器通用 | 任意(向量) | SVG | icon |
convert icon.png -define icon:auto-resize=16,32,48,64 favicon.ico| 現象 | 原因 | 解決 |
|---|---|---|
| IE 不顯示 | 需 .ico 格式、放根目錄或明確 link | 提供 /favicon.ico 並加 link rel="icon" type="image/x-icon" |
| 更新不生效 | 瀏覽器強力快取 | 加查詢字串 ?v=2、清除快取、或設定 Cache-Control |
| HTTPS 網站圖示不顯示 | 混合內容阻擋 | 確保 href 使用相對路徑或同域 HTTPS |
<head>
<!-- SVG 為主,ICO 為舊瀏覽器備援 -->
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="manifest" href="/manifest.json" />
<meta name="theme-color" content="#0066cc" />
</head>
Favicon 設定雖小,卻關乎品牌專業度與用戶體驗。**現代標準:SVG 主力 + ICO 備援 + Manifest + Apple Touch Icon**。使用 RealFaviconGenerator 一鍵生成全套檔案與 HTML 片段,部署後驗證各裝置顯示正常,即可一勞永逸。