Correctly Displaying Your Logo With CSS

Written by , Published On 26th February 2009.
Filed in CSS.

Every site has a logo, and whether it’s a page filling feature or a small design element, it often forms the primary title feature of your page. This article will show you how to implement a logo using correct semantic markup and simple HTML code, with all the presentation done via CSS.

It’ll ensure that those browsing your site without images will see a decent alternative, and provide search engines with a correct representation of your page title.

Let’s start with with HTML code. It needs to be as simple as possible, showing only the name of your site/logo enclosed within header tags and a link:

1
<h1><a href="http://designshack.net">Design Shack</a></h1>

Now once you have the HTML code in place, it’s simply a case of styling it with some straight forward CSS.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
h1 {
	text-decoration:none;
	border:0;
	width : 162px;
	height : 113px;
	margin : 0;
	padding : 0;
	background : url(/images/logo.gif) no-repeat 0 0;
}
 
h1 a {
	display : block;
	height : 113px;
	text-indent : -9999px; 
}

This CSS does two main things:

  • It tells the browser to create a certain area for your logo, and apply a background
  • It moves the actual text to display out of view (9,999 pixels to the left)

If someone browses to your site with CSS and images enabled, they’ll see your beautiful logo. If not, the background image won’t display – but the text indent won’t be applied either – meaning they’ll see your heading text as normal. Perfect!

It’s a simple but effective way to ensure your logo displays correctly, remains accessible, and is picked up correctly by search engines.

Discussion

  1. Trent says:

    Good solid tip… covers all the bases.

  2. thanks…it`s really a good way to display your logo. i also make it this way on my websites. Nice and simple

  3. Mark Kordon says:

    The debate regarding SEO and text-indent is a never ending story.

    But does anywone know what the searchengines says?

  4. Pascal says:

    search engines browse the html code, therefore won’t be influenced by any styling Mark.
    that’s the point of this technique, the genius of css in general: separating content from style.

  5. Ben says:

    Of course we now have the debate of usingup the H1 tag across the site, thus deflating it’s SEO usefulness…

  6. AJP says:

    Phew! My method makes sense!

    But yeah, I generally replace the H1, with a div or a p, as Ben mentions about deflating SEO usefulness for H1.

  7. Rob Russo says:

    Thanks for the simple breakdown. But if you don’t use H1 for this, what would be the best use?

  8. I find this a big waste of a H1 tag. The logo could simply be put inside a div with the text out of view.

    The H1 tag should be used to best describe the page it is on. For example, the H1 of this page should be “Correctly Displaying Your Logo With CSS”. This would be a far better option from an SEO point of view.

  9. Richard says:

    I’d agree with the comments above – the H1 should (ideally) be unique to the page, and not be an element which is going to be repeated on every page.

    I usually wrap the logo in a div/p and do the same thing if needed.

  10. Creamy CSS says:

    Helpful tip! I’m just going to use it very soon, thanks for post ;)

  11. Ryandc says:

    Great little article for those not currently displaying the logo with CSS, but it’s not really best practice to make the H1 the logo (as mentioned by other commenters), unless you dynamicly change the text of the image to the page title, but even that would be best featured somewhere else.

    Great simple article though, would be ncie to see more like this!

  12. Thanks for all the info about the H1 tag, I’ve always used it for the site heading in my projects and never really thought otherwise.

    Worth thinking about for future sites!

  13. shpyo says:

    David,
    1. I can’t agree with that you put logo in h1. H1 should go for article (this is the most important thing on this page). More – it’s better for SEO.
    2. Google, I was testing Google algoritm for text-indent, and I must say that Google sees text normally.

  14. Kalle says:

    From my scouring the web on this subject, the general consensus seems to be to use H1 for the logo on the _home page_, where it makes sense to do so.

    On all content pages H1 should be the main title of the page.

  15. Ape Web says:

    Can I just mention that this is not the correct way to do this, there is no correct way.

    I would also like to point out that CSS styles the page, so if the company has a logo it should be included as an image in the page, even if the CSS is not applied so I don’t like this way of showing your company logo. Nor do I like the indent hack.

  16. shae says:

    Klaye Morrison: Not only does using The H1 help with SEO, but its also good for accessibility. this technique is not for clean CSS.

    I try to use it on all of my sites, and have been for quite some time.

    there is not a single drawback- that I know of.

  17. Patrick says:

    Seconding Shae, it works great for SEO. One thing I add, though- you may want to change the h1 on each section so it properly represents where you are on the site.

    For instance:

    Homepage- joe’s widgets
    About Us- joes’ widgets: about us

    It seems to help a bit more, and to me it gives non-visual browsers even more help in navigating the page.

  18. Paul says:

    In terms of accessibility, there are some that would argue that it is not entirely accessible. In the case of images-off-css-on, you will be left with a blank space.

    I think it is a fair comprimise personally as I do struggle to think of a scenario where someone would be browsing with images diabled and CSS enabled.

  19. Peter says:

    The one problem that I have found with this method is that background images do not usually show up on a printed page, so you end up with a page of print with no title/heading.

  20. Jason says:

    Another drawback with the method of using the h1 tag with updated text for each page-

    You’re turning the title of every other page into a link to the home page. To me this seems strange, and it would be better for users with either images, CSS, or both turned off to see either the company name in the form of the image’s alt text, or the image itself.(I agree with Ape Web above – if the logo is included as a background image, then CSS lacking browsers will not see the logo)

  21. Fitness says:

    It seems that i can’t change the H1 and it’s the same on every page

  22. that seems lkike its the template it is on then

  23. Hotele spa says:

    Thank you very much this will help mov­ing forward.

Leave Your Reply