New Feature: Playlist Center! Pick a topic and let our playlists guide the way—like a learning mixtape.

Start learning with our library of video tutorials taught by experts. Get started

Improving SEO Using Accessibility Techniques
Illustration by

Creating a proper image header with CSS


From:

Improving SEO Using Accessibility Techniques

with Morten Rand-Hendriksen

Video: Creating a proper image header with CSS

A common element in websites is an image header. By that, I mean the use of a large image or logo image at the top of every page, like you see right here, this large image header. This ensures a visual identity and can be impactful. However, the logical way of doing it, simply adding an image to the top of the page, it's not really the correct way of doing it. If you add an image, you're not providing a header with text content, just a link to an image. There's a better way of doing this. With some clever CSS, you can get a header that has the correct text elements and still displays as if it was an image inside browsers, and you can make that header image link back to the home page just as if it was an image.
Expand all | Collapse all
  1. 3m 3s
    1. Welcome
      1m 4s
    2. Using the exercise files
      1m 59s
  2. 8m 16s
    1. Accessibility and SEO: A primer
      4m 58s
    2. Understanding the benefits of accessibility and SEO
      3m 18s
  3. 11m 26s
    1. Experiencing an inaccessible web site
      6m 4s
    2. Experiencing an accessible web site
      5m 22s
  4. 16m 28s
    1. Evaluating screen readers for Windows and Mac
      5m 56s
    2. Installing browser development tools
      4m 8s
    3. Pretending to be a screen reader
      6m 24s
  5. 7m 40s
    1. Installing SEO tools
      2m 30s
    2. Understanding how search engines search a page
      2m 45s
    3. Comparing sites that are SEO-friendly with ones that are SEO-unfriendly
      2m 25s
  6. 44m 6s
    1. Defining a language for a page
      5m 4s
    2. Defining meta headers for a page
      6m 10s
    3. Creating better semantic markup with HTML5
      3m 13s
    4. Using and hiding section headings
      4m 56s
    5. Creating content hierarchies with heading tags
      5m 29s
    6. Emphasizing content in paragraphs
      5m 36s
    7. Making accessible block quotes
      3m 22s
    8. Using some new HTML5 tags
      4m 47s
    9. Using ordered and unordered lists
      5m 29s
  7. 22m 17s
    1. Marking up links properly
      6m 48s
    2. Marking up images
      7m 23s
    3. Creating a proper image header with CSS
      8m 6s
  8. 32m 43s
    1. Creating an accessible menu with an unordered list
      6m 16s
    2. Creating and hiding nav headings and skip navigation links
      6m 59s
    3. Giving navigation links proper focus with style
      4m 39s
    4. Creating an accessible drop-down menu
      10m 46s
    5. Scrapping drop-down menus for better options
      4m 3s
  9. 3m 44s
    1. Next steps
      3m 44s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
please wait ...
Improving SEO Using Accessibility Techniques
2h 29m Intermediate Dec 06, 2011

Viewers: in countries Watching now:

This course focuses on two elements of web development: accessibility and search engine optimization (SEO), demonstrating why they are important and how they work. Author Morten Rand-Hendriksen also shows how good coding practices and modern web standards can make a site accessible and more visible to search engines and social networks.

Topics include:
  • Understanding the benefits of accessibility and SEO
  • Evaluating screen readers for Windows and Mac
  • Installing browser development tools
  • Comparing sites that are SEO-friendly and SEO-unfriendly
  • Defining a language for a page
  • Creating better semantic markup with HTML5
  • Marking up images and links properly
  • Creating an accessible menu with an unordered list
Subjects:
Business Web Accessibility SEO
Author:
Morten Rand-Hendriksen

Creating a proper image header with CSS

A common element in websites is an image header. By that, I mean the use of a large image or logo image at the top of every page, like you see right here, this large image header. This ensures a visual identity and can be impactful. However, the logical way of doing it, simply adding an image to the top of the page, it's not really the correct way of doing it. If you add an image, you're not providing a header with text content, just a link to an image. There's a better way of doing this. With some clever CSS, you can get a header that has the correct text elements and still displays as if it was an image inside browsers, and you can make that header image link back to the home page just as if it was an image.

That sounds confusing until you see how it's done. So let's first take a look at what we have right now and why this isn't the right way of doing it. So what I have here at the top is this big image, and if you click on it you go back to the home page, so it seems like it works the way it's supposed to. Yes? Well, if we turn Styles off and then disable his image by breaking the link, you immediately see the problem. Because it was an image, there is no text information here.

So for a person who's not seeing the image, what they see is the first piece of text information, namely Main Menu, which is the menu header for the Main Menu, hardly what you want to display as a title of your site. A better option would be to add actual text as your header, but if you do that, then you don't have the image. Well, you can't have the image, but you have to know how to do it. So first I'm going to add just the text I want in the header and then we'll add the image afterwards. So let's go to the mark up in our project file and take a look at what it looks like right now.

So when we scroll down, you'll see here on line 18 we have this div id="header-image" and then there's an anchor and then the image itself. So what I want to do is replace this with some text. So first, I'm going to a new HTML5 element called hgroup. This is not age group, as in the age of a person; it's hgroup as in group of headings. So I'll end that type first so that there's no confusion, and then inside here I want to add both an h1 and an h2 header, because I want the h1 to say Hansel & Petal Flower Company and I want the h2 to say, from our garden to your home, which coincidentally matches what the graphic says right here.

So I'll add an h1 first. Say Hansel & Petal Flower Company, and then I'll add the h2. It says, From our garden to your home. And then because I want this to be a link, I'll add a link around Hansel & Petal Flower Company. So I'll go down here and I'll simply borrow the link code from the image we had before and I'll wrap it around the text, Hansel & Petal Flower Company.

Then because this link is a link, it needs a title tag, so I will say title=Hansel & Petal Flower Company home page. Now I can delete the code that calls the image and save the page, and when we go back to the page now, you'll see, instead of the image, we have this Hansel & Petal Flower Company link, and then the subtitle. The next step is to add the image back in. So here I want to do two things.

I want to add the image as a background element, and then I also want to hide the text. This is all done in CSS, but first we need to create some IDs to attach CSS to. So I'll go back into my markup, and then for the h1, I'll add the id="site-title" and for the h2 I'll add the id="site-description". Now I can create CSS styles that hook up to these IDs. I'll go and open my style sheet and then under Header I can add some new styles.

So I'll go here and I'll create a new style called site-title, because that's the new ID, and then I'll say a, because I want to target the anchor inside, meaning the link. The reason why I do this is because I want the image I place there to become clickable so that I can go back to the home page. Now, I need to add the background image. So I will say background: url and then I'll point to the image. In this case it's under images/headerBanner.png.

I don't want this image to repeat, so I'll just set it to no-repeat and then I can now save it. So I've saved the style sheet and index.html page and I'll reload it in my browser. Now you see we have the background image, but the background image only spans the length of the text itself. I want the background image to be the same size it was before. So what I want to do is match the size of this box to the size of the image itself. I already know that the image is 183 pixels tall and 900 pixels wide, so I can go in and add that to my styles.

So I go and add a new line and say height: 183px and then width: 900px, and because I want it to display as a block element so that it wraps around, I have to set display to block. Now when I reload the page, you'll see the image is the size I want, and you notice that wherever I hover inside the image, it's clickable. So I'm almost where I want to be. The only thing that's missing is that I can still see the text Hansel & Petal Flower Company.

So I need to get rid of that. And I'm going to do this the same way we got rid of the section header. So I'll go in and finally say text-indent:-9999px. Reload one final time, and you see now the text is gone because it's been indented to the left so far that you can never see it. That leaves us with just one problem, the subtitle From our garden to your home. We need to get rid of that as well. So I'll go back in and create a new style for the site-description, and I'll use the same text indent trick we did with the section-headers.

So I'll first position it absolutely, and then I'll do text-indent. Reload the page and we now have that header image clickable, containing the text information we need, and it doesn't display the text. So if now go and Disable Styles, you'll see that the header of the page now is Hansel & Petal Flower Company, From our garden to your home, rather than nothing.

Of course, this still doesn't look exactly the way we want it to. I need to work a bit on my margins here and get rid of that hover effect, but that can be done later on. This is the general principle of adding a proper page header and you can also use this to create any other image buttons, so that the image buttons always contain real text, in case the image doesn't work. By adding and hiding header text at the top of your site and adding an image background to the header, you get all the benefits with none of the pain.

The page has a proper text header readable by browsers, people, and search engines alike, and for those using a visual browser the image and logo will display as intended. The same technique can and should be used any time you want to replace text with an image. That way you preserve the text semantics, and still get the graphic display.

There are currently no FAQs about Improving SEO Using Accessibility Techniques.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

join now Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Improving SEO Using Accessibility Techniques.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Notes cannot be added for locked videos.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.