I use font-awesome and display their fonts like that:
<i class="icon-lock"></i>
This will display a nice little lock symbol. For the user to know what exactly that means, I tried adding attributes such as title and alt, but to no avail.
Is there any attribute I can use for the <i>
tag that executes the same task as alt for images and title for links?
Italic elements do not support alt attributes, IMG elements do. If you want an ALT attribute, use an image.
“alt” is for providing an image alt tag to describe the image to the search engine crawlers and the screen readers for better web accessibility. “title” is for providing an explanation of the image alt tag and image URL within the “src” attribute.
The alt and title attributes of an image are commonly referred to as 'alt tag' or 'alt text', and 'title tag'. (Technically they're not tags, they're attributes, but you don't need to worry about that). These attributes allow you to add textual descriptions of your image, which can help with both SEO and accessibility.
Definition: An alt tag, also known as "alt attribute" and "alt description," is an HTML attribute applied to image tags to provide a text alternative for search engines.
You can use the title
attribute on an i
element, like any element, e.g.
<i class="icon-lock" title="This symbolizes your being locked inside"></i>
Whether it helps is a more difficult issue. Browsers usually show the title
attribute value as a “tooltip” on mouseover, but why would the user mouse over the icon? And such tooltips are of poor usability; so-called CSS tooltips often work better.
Screen readers may give the user optional access to title
attributes, but I’m not sure what they do with elements with empty content.
With the advance of WAI-ARIA, when using font icons, you probably should use a combination of the following to improve accessibility:
Authors MAY, with caution, use aria-hidden to hide visibly rendered content from assistive technologies only if the act of hiding this content is intended to improve the experience for users of assistive technologies by removing redundant or extraneous content. Authors using aria-hidden to hide visible content from screen readers MUST ensure that identical or equivalent meaning and functionality is exposed to assistive technologies.
I don't know your exact use case, so I take the liberty to use the simpler case of providing a phone number. In decreasing order of preference, I would use:
<span aria-label="Our phone number"> <span class="icon-phone" aria-hidden="true"></span> +33 7 1234576 </span> (or any variation implying: - an `i` element with a `role` presentation attribute instead of the inner `span` element - a `title` attribute instead of an `aria-label` attribute)
<span class="icon-phone" aria-label="Our phone number">+33 7 1234576</span> (or any variation using `title` instead of `aria-label`)
<i class="icon-phone" role="presentation" aria-label="Our phone number">+33 7 1234576</i> (or any variation using `title` instead of `aria-label`)
Please note that aria-label and title attributes should describe the content of the element. Not the next sibling element. So I feel like the following solution is not in accordance with the specs (even if most accessibility tools would actually have the same observable behavior as if the phone number were actually inside the span
element) :
<span class="icon-phone" title="Our phone number"></span>+33 7 1234576
You should use <span>
or something along those lines instead. You can use the title=""
attribute to give some text on hover, if that's what you're looking for. As far as providing accessability to screen readers, or SEO value, you could add the following CSS:
.icon-lock{
text-indent:-99999px;
}
And then write your markup like so:
<span class="icon-lock">What I want the screen reader to say</span>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With