What is the proper way to display a logo with CSS?
Asked Answered
R

4

16

I've been learning CSS recently, and the tutorial series I'm watching says the best way to display a logo image is to wrap the text in an H1 tag, then set the CSS style for that tag to background image, with a text indent of -99999 or similarly large number.

This seems incredibly hackish and inelegant. It also seems like using CSS to hide text would be a big no-no for SEO purposes (as hiding text via CSS is frowned upon).

I've also read that using an img should be avoided, as the logo itself is not really content, so should be relegated to the design-side of the coding (i.e. CSS).

What is the current consensus on this?

Ripply answered 12/4, 2012 at 14:12 Comment(3)
Why is the logo itself not really content?Earthiness
Check this #7996002Wry
Whomever told you that logos are "not really content" is incorrect.Taimi
T
18

The correct way to display a Logo is with an <img> element. If you haven't studied logos and logotype, you might not realize that a logo has its own semantics and is required to be presented in a very specific manner. It may also have a required interpretation, which is what should be used in the [alt] attribute.

If that required interpretation is legitimately a heading in the page, it would be semantically correct to add it to a <h#> element:

<h1>
    <img src="logo.png" alt="Foo Co.: Where everyone can fizz the buzz" />
</h1>

Typically the logo is used as a link, so it's common to see:

<a href="/">
    <img src="logo.png"... />
</a>

Additionally the logo can be emphasized (could be either <strong> or <em> depending on degree):

<strong>
    <a href="/">
        <img src="logo.png" ... />
    </a>
</strong>

To understand the semantics of a logo. If you're referencing the Coca-cola company, the logo for the brand would not, and should not change if you swapped out, or removed a stylesheet. Most people understand that semantically,

the Coca-Cola logo

is different from

the Pepsi logo

Taimi answered 12/4, 2012 at 14:20 Comment(0)
T
9

I always just wrap an anchor tag around an image:

<a href=""><img src=""></a>

or create the anchor tag as a block and set a background image

<a class="logo" href="">Logo</a>

.logo { 
         background: url("/path") no-repeat; 
         width: 100px; 
         height: 100px; 
         display: block; 
         text-indent: -9999px;
}
Thurston answered 12/4, 2012 at 14:15 Comment(0)
S
6

You should always use img to display the logo. Using h1 and using the logo as background is a really bad practice and should be avoided. Your logo is the content and not a h1.

Harry Roberts has explained it clearly in his post - Your logo is an image, not a <h1>

Shambles answered 12/4, 2012 at 14:22 Comment(0)
A
2

I think it doesn't really matter. There are many different ways of doing this, and they're all supported. They all work. Most of them are search engine-friendly and perfectly accessible.

I would do something like this:

<h1><a href="/"><img src="rsc/logo.jpg" alt="Frobozz Company"></a></h1>

Search engines, text-mode browsers and screen readers see the alt text, everyone else sees the logo image.

Approximate answered 12/4, 2012 at 14:18 Comment(1)
From a branding and marketing standpoint, it is very important to correctly present logotype. Placing a logo in CSS would be an incorrect approach. To that affect, it does matter.Taimi

© 2022 - 2024 — McMap. All rights reserved.