tags:

views:

9266

answers:

9

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 a logo that links to the homepage. I want to do the same, while best optimizing for search engines, screen readers, IE 6+, and browsers who have disabled CSS and/or images.

Example One: Doesn't use an h1 tag. Not as good for SEO, right?

<div id="logo">
    <a href="">
        <img src="logo.png" alt="Stack Overflow" />
    </a>
</div>

Example Two: Found this somewhere. The CSS seems a little hacky.

<h1 id="logo">
    <a href="">Stack Overflow</a>
</h1>

/* css */
#logo {
    padding: 70px 0 0 0;
    overflow: hidden;
    background-image: url("logo.png");
    background-repeat: no-repeat;
    height: 0px !important;
    height /**/:70px;
}

Example Three: Same HTML, different approach using text-indent. This is the "Phark" approach to image replacement.

<h1 id="logo">
    <a href="">Stack Overflow</a>
</h1>

/* css */
#logo {
    background: transparent url("logo.png") no-repeat scroll 0% 0%;
    width: 250px;
    height: 70px;
    text-indent: -3333px;
    border: 0;
    margin: 0;
}

#logo a {
    display: block;
    width: 280px; /* larger than actual image? */
    height: 120px;
    text-decoration: none;
    border: 0;
}

Example Four: The Leahy-Langridge-Jefferies method. Displays when images and/or css is turned off.

<h1 id="logo" class="logo">
    <a href="">Stack Overflow</a>
</h1>

/* css */
h1.logo {
    margin-top: 15px; /* for this particular site, set this as you like */
    position: relative; /* allows child element to be placed positioned wrt this one */
    overflow:hidden; /* don’t let content leak beyond the header - not needed as height of anchor will cover whole header */
    padding: 0; /* needed to counter the reset/default styles */
}

h1.logo a {
    position: absolute; /* defaults to top:0, left:0 and so these can be left out */
    height: 0; /* hiding text, prevent it peaking out */
    width: 100%; /* 686px; fill the parent element */
    background-position: left top;
    background-repeat: no-repeat;
}

h1#logo {
    height: 60px; /* height of replacement image */
}

h1#logo a {
    padding-top: 60px; /* height of the replacement image */
    background-image: url("logo.png"); /* the replacement image */
}

What method is the best for this sort of thing? Please provide html and css in your answer.

Thanks!

A: 

I think example one is more than enough as alt text will be shown if images are disabled. This wil also help search engines to know about your site.

Update : Looks like I was wrong. Check this article.

Shoban
+1  A: 

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 */  }
Rob Knight
What's wrong with indenting? My assumption was that screenreaders and crawlers still pick up the text despite indentation.
ckarbass
Sorry it took me so long to get back here. The only issue with indenting is if images are disabled in the user's browser but CSS is on, nothing appears, text or images. It's kind of an edge case, but important to consider for me, working on a university website.
Rob Knight
hmm...I couldn't get this to work. The anchor text kept appearing on top of the image.
Andrew
<nitpicker> use #logo span instead, it will be more efficient for the browser to render </nitpicker>
Chris Missal
+3  A: 

If accessibility reasons is important then use the first variant (when customer want to see image without styles)

<div id="logo">
    <a href="">
        <img src="logo.png" alt="Stack Overflow" />
    </a>
</div>

No need to conform imaginary SEO requirements, because the HTML code above has correct structure and only you should decide does this suitable for you visitors.

Also you can use the variant with less HTML code

<h1 id="logo>
  <a href=""><span>Stack Overflow</span></a>
</h1>
/* position code, it may be absolute position or normal - depends on other parts of your site */
#logo {
  ...
}

#logo a {
   display:block;
   width: actual_image_width;
   height: actual_image_height
   background: url(image.png) no-repeat left top;
}

/* for accessibility reasons - without styles variant*/
#logo a span {display: none}

Please note that I have removed all other CSS styles and hacks because they didn't correspond to the task. They may be usefull in particular cases only.

Regards, Pavel

se_pavel
+1  A: 

I think you'd be interested in the H1 debate. It's a debate about whether to use the h1 element for the page's title or for the logo.

Personally I'd go with your first suggestion, something along these lines:

<div id="header">
    <a href="http://example.com/"&gt;&lt;img src="images/logo.png" id="site-logo" alt="MyCorp" /></a>
</div>

<!-- or alternatively (with css in a stylesheet ofc-->
<div id="header">
    <div id="logo" style="background: url('logo.png'); display: block; 
        float: left; width: 100px; height: 50px;">
        <a href="#" style="display: block; height: 50px; width: 100px;">
            <span style="visibility: hidden;">Homepage</span>
        </a>
    </div>
    <!-- with css in a stylesheet: -->
    <div id="logo"><a href="#"><span>Homepage</span></a></div>
</div>


<div id="body">
    <h1>About Us</h1>
    <p>MyCorp has been dealing in narcotics for over nine-thousand years...</p>
</div>

Of course this depends on whether your design uses page titles but this is my stance on this issue.

Ross
I'm pretty sure IMG's are considered content whereas css background images aren't. That's why I tend to lean towards background images for site-wide images and things of that nature that aren't explicitly for that page content.
Joe Philllips
@d03boy: Well in that case you could make an inline div that has the correct sizing for the logo size and give that the background. A span inside it (that has visibility: hidden;) will provide an "alt text" replacement.
Ross
H1 debate is now a dead link
alex
+11  A: 

You're missing the option:

<h1>
  <a href="http://stackoverflow.com"&gt;
    <img src="logo.png" alt="Stack Overflow" />
  </a>
</h1>
Rahul
does wrapping an h1 around an image with alt text carry the same weight (seo-wise) as plain text wrapped with an h1?
Andrew
It should, that's the purpose of the alt attribute - to function as text for those that can't see images.
Rahul
By the way, it is relevant, a logo is part of your website content, it is not used for decoration, so use <img> with alt attribute not CSS for your logo.
Boris Guéry
Matt Cutts answering this question. http://www.youtube.com/user/GoogleWebmasterHelp#p/search/0/fBLvn_WkDJ4
troynt
A: 
<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;
}
Daniel Boundy
A: 

you miss title in element.

Stack Overflow

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 he/she hover on logo.

30ml
A: 

this is helped.Thanks :-)

monika
A: 

I made a plugin to ease this process for non techies. http://www.wp1stop.com/h1-tag-seo-optimizer/

Frederick