Everyone has one, either your name, your logo or some cute picture you use to discern that the user has landed on your little piece of the web. Here’s mine just for reference.

But there is a specific optimal way to include it on your page.

The things to concern here.

  • Any images you add to page that are not content related but are theme related pollutes your markup with un-necessary elements and makes it harder to re-skin in the future.
  • Search engines can’t read text from an image, so your primary identification doesn’t get indexed.
  • If images aren’t loaded (hey it happens, really!) they the visitor doesn’t know where they are. There is the alt text of the image that doesn’t load, but its size in comparison to the rest of the page is very poor.
  • What if you want to change your logo based on the page your on, or user activity, you’ll need to change the img src, meaning script, or markup changes per page.

There’s probably a few more, but you get the idea, beyond the Happy Path, using an image for your logo starts to cause problems.

The solution is actually beautiful in its simplicity, here’s the markup you’ll want to generate.

  1. <a id="logo" href="[Your Site Address Here]" title="[Your Site Name Here]">
  2.         <h1>
  3.             [Your Site Name Here]
  4.         </h1>
  5.     </a>

and then you can pair this with some simple CSS to add our logo image.

  1. a#logo { display:block; width: '[logo width]'; height: '[logo height]'; background: url('[logourl]') no-repeat; }
  2. a#logo h1,
  3. a#logo h2 { display: none; }

And then your pretty much done, here’s what I would end up with for my site.

  1. <a id="logo" href="http://www.justise.com" title="Kris Gray">
  2.         <h1>
  3.             Kris "Justise" Gray
  4.         </h1>
  5.     </a>
  1. body { background: maroon; }
  2. a#logo { display:block; width: 185px; height: 63px; background: url(http://www.justise.com/wp-content/themes/justise/images/headerLogo.png) no-repeat; }
  3. a#logo h1,
  4. a#logo h2 { display: none; }

Why is this markup preferable?

If we render without images, and CSS, we still get a very big peice of text that lets the user know where they are.

What the Logo Looks like without CSS

What the Logo Looks like without CSS

We also use an H1 or an H2 (more on that later) to mark our logo text so that search engines realize that the text is important and they should give a large amount of weight to that text.

It was a question of mine at some point writing this if Search Engines really do index text that is hidden with display none? So I went and looked it up, and according to this SEO optimization post on “Do search engines index that” the answer is Yes, so lets move on.

We attach the image of our logo to the background image of the logo link, so we still have the flexibility of changing our logo at any time by just updating the CSS, while also being able to change the logo link based on its context in the document, such as a different parent class.

We will obviously want our logo linked back to the main page, its just a common standard, and so you’d need pretty much the same amount of markup if you were going to just insert an image.

Lastly, this w3c article on using the H1 tells us that we want to mark the most important text on the page with the H1 element. Since on the main page, that is most likely our logo this is fine, but on sub pages, we’ll probably want the title of each blog post as the H1, so we’ll want to make our logo now an H2. With the technique we are using here, it requires no change to the CSS, just a simple markup change.

No comments