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

前端 未结 15 2154
渐次进展
渐次进展 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:49

    Chiming in a bit late here, but couldn't resist.

    You're question is half-flawed. Let me explain:

    The first half of your question, on image replacement, is a valid question, and my opinion is that for a logo, a simple image; an alt attribute; and CSS for its positioning are sufficient.

    The second half of your question, on the "SEO value" of the H1 for a logo is the wrong approach to deciding on which elements to use for different types of content.

    A logo isn't a primary heading, or even a heading at all, and using the H1 element to markup the logo on each page of your site will do (slightly) more harm than good for your rankings. Semantically, headings (H1 - H6) are appropriate for, well, just that: headings and subheadings for content.

    In HTML5, more than one heading is allowed per page, but a logo isn't deserving of one of them. Your logo, which might be a fuzzy green widget and some text is in an image off to the side of the header for a reason - it's sort of a "stamp", not a hierarchical element to structure your content. The first (whether you use more depends on your heading hierarchy) H1 of each page of your site should headline its subject matter. The main primary heading of your index page might be 'The Best Source For Fuzzy Green Widgets in NYC'. The primary heading on another page might be 'Shipping Details for Our Fuzzy Widgets'. On another page, it may be 'About Bert's Fuzzy Widgets Inc.'. You get the idea.

    Side note: As incredible as it sounds, don't look at the source of Google-owned web properties for examples of correct markup. This is a whole post unto itself.

    To get the most "SEO value" out HTML and its elements, take a look at the HTML5 specs, and make make markup decisions based on (HTML) semantics and value to users before search engines, and you'll have better success with your SEO.

    0 讨论(0)
  • 2020-11-28 00:52
    <h1>
      <a href="http://stackoverflow.com">
      Stack Overflow<img src="logo.png" alt="Stack Overflow" />
      </a>
    </h1>
    

    This was the good option for SEO because SEO gives the H1 tag high priority, inside the h1 tag should be your site name. Using this method if you search the site name in SEO it will show your site logo as well.

    you want to hide the site name OR text please use text-indent in negative value. ex

    h1 a {
     text-indent: -99999px;
    }
    
    0 讨论(0)
  • 2020-11-28 00:55

    I do it mostly like the one above, but for accessibility reasons, I need to support the possibility of images being disabled in the browser. So, rather than indent the text from the link off the page, I cover it by absolutely positioning the <span> to the full width and height of the <a> and using z-index to place it above the link text in the stacking order.

    The price is one empty <span>, but I'm willing to have it there for something as important as an <h1>.

    <h1 id="logo">
      <a href="">Stack Overflow<span></span></a>
    </h1>
    
    #logo a {
       position:relative;
       display:block;
       width:[image width];
       height:[image height]; }
    
    #logo a span {
       display:block;
       position:absolute;
       width:100%;
       height:100%;
       background:#ffffff url(image.png) no-repeat left top;
       z-index:100; /* Places <span> on top of <a> text */  }
    
    0 讨论(0)
  • 2020-11-28 00:56

    You're missing the option:

    <h1>
      <a href="http://stackoverflow.com">
        <img src="logo.png" alt="Stack Overflow" />
      </a>
    </h1>
    

    title in href and img to h1 is very, very important!

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

    I don't know but this is the format have used...

    <h1>
        <span id="site-logo" title="xxx" href="#" target="_self">
            <img src="http://www.xxx.com/images/xxx.png" alt="xxx" width="xxx" height="xxx" />
            <a style="display:none">
                <strong>xxx</strong>
            </a>
        </span>
    </h1>
    

    Simple and it has not done my site any harm as far as I can see. You could css it but I don't see it loading any faster.

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

    A new (Keller) method is supposed to improve speed over the -9999px method:

    .hide-text {
    text-indent: 100%;
    white-space: nowrap;
    overflow: hidden;
    }
    

    recommended here:http://www.zeldman.com/2012/03/01/replacing-the-9999px-hack-new-image-replacement/

    0 讨论(0)
提交回复
热议问题