SEO friendly H1 images

H1 image replacement

H1 image replacement


A lot of the time, at the top of your website you’ll want to use something a bit more impressive than a simple H1 tag. The obvious solution would be to replace it with an image, but then you don’t have a H1 anymore and it makes good SEO sense to keep them on your pages. I’m going to show you a way of replacing your H1 text with an image and the search engines will continue to read it.

First create your H1 tag on your page. Remember to be as descriptive as you can be (this is the one of the main things that search engines pick up on).

<h1>Your site description goes in here</h1>

Let’s say for example that you would like your company logo in here, and you need it to appear on every page. We will need to add the image we want and hide the text using CSS. You will also need to add height and width values to match the size of the image you are using. To hide the text we use a text indent of -9999em which put’s it way off the screen. You’ll notice that if you put 9999em instead your text is still hidden, but your page is now about 6 feet wide. :)

Here’s the CSS:

h1{
height: 150px; /*change these to match your image size*/
width: 400px;
background-image: url('your_logo_goes_here');
background-repeat: no-repeat;
background-position: left top;
text-indent: -9999em;
}

disable styles

disable styles

The text is hidden yet the search engines will easily find it at the top of your page (search engines completely disregard all CSS styles). A good way to test this (and other SEO techniques) is to disable all CSS using the web developer toolbar on Firefox. This will give you a visual overview of what the search engine will see, and in what order.

A lot of sites have a link on their logo and header which take you back to the homepage and so it would be nice if we could do that and still use the H1. Adding the link to the H1 is easy enough, but it’s wrapped around the text that is indented off the screen so it can’t be clicked.

Here’s the HTML mark up…

<h1><a href="#">Here is my H1 image and link test</a></h1>

and the CSS…

h1{
background-image:url(images/tile.png);
height: 20px;
width: 200px;
text-indent: -9999em;
margin: 50px;
}
h1 a{
padding-right: 9999em;
display: inline-block;
width: 200px;
height: 20px;
}

That works but it’s got a bit of a problem. The link stretches all the way to the left. If you change the link to display: block; then that stretches all the way to the right. Ok if your logo is right up to one edge but still not a great solution.

This time I will do away with text indents and try a different way of hiding the text. Hiding either the H1 or the link will cause the link to just dissapear. We still want the link, just not the text inside it. Enter our friend <span>. By adding a span around the text in the link we can now hide it without hiding the link.

mark up with span added.


<h1><a href="#"><span>Here is my H1 image and link test</span></a></h1>

the CSS is much cleaner now.

h1{
background-image:url(images/tile.png);
height: 20px;
width: 200px;
margin: 50px;
}
h1 a{
display: inline-block;
height: 20px;
text-decoration: none;
}
h1 a span{
visibility: hidden;
}

The above code and CSS now hides the text but keeps the link and the image in the correct place. Both the HTML and CSS validate and if styles are disabled then your normal H1 text shows up. As far as I can tell, the only downside to this solution is that if images are disabled then you see nothing. However having both images and styles disabled works fine. You could write some javaScript to counter this but would someone with images disabled have javascript on? I doubt it!

Tags: , , , , , ,

6 Responses to “SEO friendly H1 images”

  1. Rumble says:

    You can keep your link on screen by using the the text-indent approach but using a different CSS selector. Consider the following..

    Here is my H1 image and link test

    h1 a {
    background: url(../my/logo.png) no-repeat 0 0; /* Background shortcut syntax*/
    display: block; /* Makes the ‘a’ tag a block level element so we can give it a height and width */
    height: 50px;
    margin: 50px;
    overflow: hidden;
    text-indent: -9999em;
    width: 200px;
    }

    Job done!

  2. Richard Reid says:

    Alright Barry, I’m a novice designer and I came across your site while looking for tutorials on how to create a image header with searchable text so thanks for your tutorial! I’ll try it out later but also I had a question about feedback forms like your one. I’ve only used cgi scripts for forms but wondered if php forms are more secure to use and does using a capcha code stop spammers? I haven’t had a good look around your site but do you know of any good feedback form tutorials that use captcha? Or maybe some kind of validation? Any assistance greatly appreciated?

    Great site by the way and it gives me a target to aim for in the future!

    All the best!

    Cheers!

    Rich

  3. barry says:

    Hi Richard,

    As far as forms go I think PHP has taken over from CGI these days. I can’t comment on security between the two, this is usually down to the developer and how far they want to take it. I’m pretty sure you could make both types equally secure with the right coding though. The Captcha on my form is actually a wordpress plugin (I have no idea how to create those). I only installed it to stop spam and so far so good.

    Hope that helps

    Barry

  4. [...] This post was mentioned on Twitter by Hannes Krueger, Robert Chambers. Robert Chambers said: Want to improve your search engine ranking? Try using #SEO friendly H1 images: http://bit.ly/9cGxQw [...]

  5. You have made a awesome blog of ur Barry ,you were talking bout this dzine at the Wp forums 5 months back and its really amazing.N the tut is just awesome.thnx a lot

  6. Hey…..nice post!!

    Awesome, No more words to explain :) :) :D just….cool blog.

Leave a Reply