iT邦幫忙

2022 iThome 鐵人賽

DAY 18
0
Modern Web

意識界歸來的前端系列 第 18

h1 標籤 logo 常見迷思

  • 分享至 

  • xImage
  •  

此篇會探討如何運用 h1 標籤以及一些新手常見的錯誤迷思。

  • h1 用於公司名稱、logo
  • h1 logo 圖片取代文字
  • h1 文章標題

先來簡單複習一下 h1 標籤用途

MDN Heading:「Use only one <h1> per page or view. It should concisely describe the overall purpose of the content.」
白話文:「每頁或畫面上僅使用一個 h1,它應該要簡單地描述整個內容的目的。(例如:文章標題)」


h1 用於公司名稱、logo

根據在 search console help 上的這篇提問,google 有明確的提供建議:「Your h1 should be the main heading of a page and contain text that explains what the page is about. Typically that is not the name of the company that produces the website.」
白話文:「h1 應該要作為頁面主要的標題,包含解釋關於頁面內容的文字,通常,在頁面中不會作為公司名稱。」

所以不建議將 h1 標籤用於公司名稱。

方才的提問 中 google 有對 logo 圖片提出建議:「If you display a logo image, then a good move is to add an alt attribute to it that states the name of the company associated with the logo.」
白話文:「如果要顯示圖片,那麼好的做法是添加 alt 屬性,並將公司名稱設為該屬性值。」

建議使用 alt 屬性來替代 h1。

google 還有提供了另一種方法 Logo (Organization) structured data


h1 logo 圖片取代文字

上方 google 回答了「建議使用 img 標籤 alt 屬性來替代 h1」,但新手可能會覺得那是不是讓 h1 內有文字內容就可以了?

例如下方範例:「在 h1 添加文字並用 圖片取代文字 技巧隱藏」、「直接透過來設置 img 的 alt 作為 h1 文字內容」。

<!-- 透過圖片取代文字,將文字內容隱藏 -->
<h1>
  <a href="index.html">
    logo 的圖片取代文字
  </a>
</h1>

h1 a {
  background-image: url();
  width: 45px;
  height: 45px;
  display: block;
  text-indent: 101%;
  overflow: hidden ;
  word-spacing: nowrap;
}

<!-- alt 作為 h1 文字內容 -->
<h1>
  <a href="index.html">
    <img src="./images/logo.png" alt="logo">
  </a>
</h1>

下方將其拆為兩個方向來討論為什麼不推薦。

  • h1 對於 SEO 是否有幫助?
  • 使用圖片取代文字技巧是否有幫助?

h1 對於 SEO 是否有幫助?

詳細探討可以參考前面這篇文章多個 h1 標籤,結論是沒有太大的幫助,即使有影響也不大。

有興趣可以參考下方兩個文獻

使用圖片取代文字技巧是否有幫助?

根據 Google Search Central 這部 Should I include my logo text using 'alt' or CSS? 影片的回答,可以確定 img 標籤的 alt 絕對勝過 css hidden 將文字隱藏起來。


h1 範例

文章標題

最常見的用法,下方直接透過兩個網站截圖來演示。

BBC News

stackoverflow 文章

logo

logo 不是 img 無法設置 alt 情況下,還是有網站是搭配 css hidden 來設置 h1。

Apple:logo text
Tesla:logo svg


conclusion

h1 不一定只能設置 logo,且對於 SEO 來說 h1 不是最重要的,所以只要 h1 設置有符合規範以及提升整體結構(提升可讀性),去設置 h1 都不會有太大問題。


上一篇
關於圖片設置如何在 background、img 做選擇
下一篇
透過認識 element tree、document tree、box、display type 來理解 HTML 排版
系列文
意識界歸來的前端30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言