大网数据广告活动
网站运营与故障问答

Best SEO-friendly approach for icon links?

· 52CE 我爱测

I'm having trouble finding info on this. I'd like to know what is the best way to markup icon links so Search Engines can make sense of it. Google's validator tools seem to ignore title attributes. The following are 2 cases for i…

问题原文

原帖链接 · liquidRock · CC BY-SA 4.0

I'm having trouble finding info on this. I'd like to know what is the best way to markup icon links so Search Engines can make sense of it. Google's validator tools seem to ignore title attributes.

The following are 2 cases for icon link formatting I tend to use (be it in breadcrumbs or in other navigation elements)—using CSS ::pseudo element on a <span> or <i> tag, or styling a character by applying the @font-face icon font to it.

I also started implementing JSON-LD in my project, so for things like breadcrumbs, setting the "ListItem" "name" seems to tell Google what the name of the link is—at least the validator recognizes it in the JSON-LD code. When combined with RDFa or other Microdata, Google did not recognize the name without a hack, so I'm sticking to just JSON-LD for now.

I'm not sure about other search engines, as well as best general practices when using icons for links, and if using JSON-LD makes the HTML markup irrelevant.

Case 1: CSS Pseudo Element

<ol id="breadcrumbs">
    <li><a href="/" title="Home"><span class="icon-home"></span></a>&nbsp; &gt;</li>
    <li><a href="/collection-page/" id="collection-page">Collection Page</a>&nbsp; &gt; </li>
    <li><span class="current-page">Current Page</span></li>
</ol>
<style>
    .icon-home::before { font-family:'my-icon-font'; }
</style>

Case 2: A character being directly styled

<ol id="breadcrumbs">
    <li><a class="b-home" href="/" title="Home">H</a>&nbsp; &gt;</li>
    <li><a href="/collection-page/" id="collection-page">Collection Page</a>&nbsp; &gt; </li>
    <li><span class="current-page">Current Page</span></li>
</ol>
<style>
    .b-home { font-family:'my-icon-font'; }
</style>

JSON-LD

<script type="application/ld+json">
    {
        "@context": "https://schema.org/",
        "@type": "BreadcrumbList",
        "@id": "https://example.com/collection-page/current-page/#breadcrumbs",
        "itemListElement": [
            {
                "@type": "ListItem",
                "position": 1,
                "name": "Home",
                "item": "https://example.com/"
            },{
                "@type": "ListItem",
                "position": 2,
                "name": "Collection Page",
                "item": "https://example.com/collection-page/"
            },{
                "@type": "ListItem",
                "position": 3,
                "name": "Current Page"
            }
        ]
    }
</script>

已采纳解答

原帖链接 · liquidRock · CC BY-SA 4.0

I still haven't found a clear answer for making icon links easily crawlable, however using JSON-LD the schema validators at least show the search engines will see the schema if you set it up correctly and know the name of the icon link that way.

As far as accessibility, all you need to do is add an aria-label to your icon link and screen readers will see it. From what I've read, title attributes don't seem to work all the time, so adding an aria-label is the best bet.

<!-- Old code -->
<li><a href="/" title="Home"><span class="icon-home"></span></a>&nbsp; &gt;</li>

<!-- New code with aria label-->
<li><a href="/" title="Home" aria-label="Go to homepage"><span class="icon-home"></span></a>&nbsp; &gt;</li>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2021-09-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。