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
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/"><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.
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.
After reading through the above solutions, I used a CSS Grid solution.
<div class="title-stack">
<h1 class="title-stack__title">StackOverflow</h1>
<a href="#" class="title-stack__logo">
<img src="/images/stack-overflow.png" alt="Stack Overflow">
</a>
</div>
.title-stack {
display: grid;
}
.title-stack__title, .title-stack__logo {
grid-area: 1/1/1/1;
position: relative;
}
.title-stack__title {
z-index: 0;
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}