We launched a new IT training category! Check out the 140+ courses now.

Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Improving accessibility

From: Deploying Icon Fonts for the Web

Video: Improving accessibility

By now, I think we've seen some patterns emerge Here's the selector that's controlling our icon fronts, And as I scroll down, indeed, there we have User Profile with the icon beside it.

Improving accessibility

By now, I think we've seen some patterns emerge in terms of best practices when deploying icon fonts. There's one thing we need to really take care of though before we move onto the individual styling properties that we can do with the icon fonts, and that is talking about how to improve the accessibility of the icons on our page. So there are a couple of problems that can crop up in terms of accessibility. The first is if you have generated content that is injected into your HTML, screen readers will read that.

And so if it's a letter, that's really a problem but a lot of it times it can cause a screen reader to read something that the user really doesn't understand what's going on with that. The other use case where accessibility comes into play is if you're thinking about positioning an icon all by itself, obviously that's going to mean something to people looking at the layout, but it's not really going to be visible at all to folks on accessibility devices and screen readers and things like that. So, we need to address both of those. The first thing that we can do, is we can hide content from screen readers that we don't want to be read.

There's a couple of ways that we can do that. One is to use the aria hidden attribute. That's an attribute that can be applied to any HTML element. And it's either, it supports values with true and false, so what you can do is if you want to hide something from a screen reader, for example you can take that element and give it an attribute of aria hidden equals true and that's going to make the content of that element invisible to screen readers. Well, that's great and it works well and that's a perfect solution for what we're doing, but it does apply a little bit of a constraint on us.

Let's say you have a paragraph with some text and you wanted an icon to appear in front of that text. Well you can't put the aria-hidden attribute on the paragraph itself, because if you do that, it's going to hide all the content from screen readers including the icon, which isn't what you want in that instance. So that means that we have to move our icons into individual elements, which we've been doing actually by placing them in span tags. And what that does is it isolates the icon. It allows us to apply that attribute to the span tags themselves.

Of course, in doing that, we have to add a little bit of additional mark up. It's not that big of a deal. There's also a CSS property called speak, which in CSS, you can apply to any selector, and that tells screen readers not to read it as well. It's really not that widely supported, so you're putting that in there more to be future friendly than anything else. Now, the other thing, if you have a stand alone icon and you want to hide it, the best way to do that is to just surround the text, write some descriptive text next to the icon, surround it with a span tag and then just use positioning to move it off the page.

Screen readers will still read it, but people looking at the layout won't see it. So here's an example of using the Speak attribute in your CSS, right here, speak none. Notice it's just right there on the global style that we're applying for our data icons. And then, we're using a span to display the icon and then then we're using aria-hidden=true to hide it as well. Alright so what are we going to be doing for our exercise? We're going to add the user profile icon to this paragraph right here and here's the encoding for that.

And then we're going to add the user profile icon and then we're going to hide the generated content from screen readers. Below that, we want to add a stand alone icon for user profiles. That includes descriptive text that'll be read by screen readers but won't be visible on our layout. So I'm switching back to my HTML file. This is accessibility.htm. You can find this in the 03_05 directory. First thing I want to do is just go over to the CSS really quickly. I'm going to scroll down to the very bottom of this.

Here's the selector that's controlling our icon fronts, which is fine, there's nothing wrong with it. But right after content I'm going to add the speak property, and I'm just going to do speak: none. Again, this is not widely supported yet, but hopefully it will be in the future, and there's nothing wrong with going ahead and putting it in here, because we don't want this generated content to be read by screen readers. So the majority of what we're going to be doing is actually going to be done in the HTML file, so I'm going to go back to the HTML, scroll down to the paragraph down there at the bottom of it. And so here we have a paragraph with the text to User Profile, okay? So inside that I'm going to go ahead and do a span tag, and for the span tag I'm going to do a data-icon attribute.

And I'm going to make that value equal to the encoding that I can see just above that. So I'm going to do ampersand, octothorpe, X, E046, and a semicolon. So after a while it just becomes second nature to you. And of course I'm also going to use the aria hidden attribute. And I want that value to be equal to true. Then I'm going to close that and close the span tag. So, in one fell swoop, i've applied the icon, and i've also hidden the generated content from screen readers.

So that's one. I'm going to save that. So the next thing I need to do is go down into the paragraph below this, and I need to apply a user profile icon to this paragraph that's going to be visible, but I also want text that's going to be read by a screen reader. So we know how to do that. I'm going to go ahead and copy this span tag just to make life easier for myself. I'm going to copy and paste it. Here we go. Even though we want descriptive text for this icon, I'm still going to have the aria-hidden=true for the span tag. That's to prevent a screen reader reading some funky character or something if substitution occurs for that particular encoding.

Alright the next thing I'm going to do is I'm going to add another span tag directly after this one, alright? So I'm going to go ahead and throw in another span tag, and inside the span tag I'm going to type in the text that I want the screen reader to read. In this case the text's is just going to say User Profile. And you might be wondering why I'm actually adding another span tag. Well Im going to this a class, and I'm going to call this class alt-text. So it's pretty descriptive, it's alternate text and then I'm going to save that. Now you might be wondering why I don't use this existing class that we have here called profile.

Well in order to make sure that the text can't be seen on the layout but can be read by the screen reader, it needs to remain in our HTML code but it needs to not be visible. Meaning off to the the side. If I take the entire paragraph and move it off to the side, the icon goes with it. So I only need the text to go off to the side. So I've got this class all text, I'm going to go back into my base CSS. I'm going to scroll down here, and we're just going to go ahead and create a class for alt, text, and we're just going to do some really easy stuff here.

I'm just going to position this with absolute positioning and I'm going to take the left position and I'm just going to push that thing all the way over into the next room. Negative 9,999 ems. A lot of people do it to the top and the left. I figure that's just being cruel. I'm sending it far enough away as it is. So I'm going to save that, go down to my accesibility.htm and check that in the browser. And as I scroll down, indeed, there we have User Profile with the icon beside it. And then, we have the icon standing alone. The good news is, the text User Profile will be read in both instances by screen readers, but in the top version, it won't read whatever the generated content for the icon is, and in the bottom icon, the text, User Profile is not visible in the layout.

Awesome. So there's not a lot of extra work here that's required to make sure the icon fonts are accessible. It's something that you should do every single time you're using icons within your pages. It's just a better overall practice and you're creating a better experience for a large segment of users.

Show transcript

This video is part of

Image for Deploying Icon Fonts for the Web
Deploying Icon Fonts for the Web

21 video lessons · 1951 viewers

James Williamson
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
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.


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 Already a member? Log in

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 Deploying Icon Fonts for the Web.

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 preferences from 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

Your file was successfully uploaded.

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.