Replacing H1 text with a logo image: best method for SEO and accessibility?

前端 未结 15 2153
渐次进展
渐次进展 2020-11-28 00:16

It seems like there are a few different techniques out there, so I was hoping to get a \"definitive\" answer on this...

On a website, it\'s common practice to create

相关标签:
15条回答
  • 2020-11-28 00:37

    For SEO reason:

    <div itemscope itemtype="https://schema.org/Organization">
     <p id="logo"><a href="/"><span itemprop="Brand">Your business</span> <span class="icon fa-stg"></span> - <span itemprop="makesOffer">sell staff</span></a></p>
     </div>
       <h1>Your awesome title</h1>
    
    0 讨论(0)
  • 2020-11-28 00:39
    <div class="logo">
        <h1><a href="index.html"><span>Insert Website Name</span></a></h1>
        <p>Insert Slogan Here</p>
    </div>
    
    #header .logo h1 {
        background: red; /* replace with image of logo */
        display:block;
        height:40px; /* image height */
        width:220px; /* image width */
    }
    
    #header .logo h1 a {
        display:block;
        height:40px; /* image height */
        width:220px; /* image width */
    }
    
    #header .logo h1 a span {
        display:none;
    }
    
    0 讨论(0)
  • 2020-11-28 00:41

    One point no one has touched on is the fact that the h1 attribute should be specific to every page and using the site logo will effectively replicate the H1 on every page of the site.

    I like to use a z index hidden h1 for each page as the best SEO h1 is often not the best for sales or aesthetic value.

    0 讨论(0)
  • 2020-11-28 00:43

    How W3C does?

    Simply have a look a look at https://www.w3.org/. The image has a z-index:1, the text is here but behind because of the z-index:0 coupled to the position: absolute;

    The original HTML:

    <h1 class="logo">
        <a tabindex="2" accesskey="1" href="/">
            <img src="/2008/site/images/logo-w3c-mobile-lg" width="90" height="53" alt="W3C">
        </a>
        <span class="alt-logo">W3C</span>
    </h1>
    

    The original CSS:

    #w3c_mast h1 a {
        display: block;
        float: left;
        background: url(../images/logo-w3c-screen-lg) no-repeat top left;
        width: 100%;
        height: 107px;
        position: relative;
        z-index: 1;
    }
    .alt-logo {
        display: block;
        position: absolute;
        left: 20px;
        z-index: 0;
        background-color: #fff;
    }
    
    0 讨论(0)
  • 2020-11-28 00:44

    You missed title in <a> element.

    <h1 id="logo">
      <a href="#" title="..."><span>Stack Overflow</span></a>
    </h1>
    

    I suggest to put title in <a> element because client would want to know what is the meaning of that image. Because you have set text-indent for the test of <h1> so, that front end user could get information of main logo while they hover on logo.

    0 讨论(0)
  • 2020-11-28 00:46
    <h1><a href="/" title="Some title">Name</a></h1>
    
    h1 a{
      width: {logo width};
      height: {logo height};
      display:block;
      text-indent:-9999px;
      background:url({ logo url});
    }
    
    0 讨论(0)
提交回复
热议问题