<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nadia Rasul</title>
    <description>The latest articles on DEV Community by Nadia Rasul (@nadiarasul).</description>
    <link>https://dev.to/nadiarasul</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F18934%2Fd24dc04c-7369-43a7-8161-3aa8d2baa6e0.jpeg</url>
      <title>DEV Community: Nadia Rasul</title>
      <link>https://dev.to/nadiarasul</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nadiarasul"/>
    <language>en</language>
    <item>
      <title>Do icons need alt attributes?</title>
      <dc:creator>Nadia Rasul</dc:creator>
      <pubDate>Sun, 19 Jul 2020 16:37:04 +0000</pubDate>
      <link>https://dev.to/nadiarasul/do-icons-need-alt-attributes-5g52</link>
      <guid>https://dev.to/nadiarasul/do-icons-need-alt-attributes-5g52</guid>
      <description>&lt;p&gt;"Hey Nadia - do icons need alt attributes?" When I got this question from a colleague a few days ago, my first instinct was to say, "it depends". Of course, I then went on to explain what it depends on, but I also realized that I get this question often enough for the answer to be turned into an easily shareable short post.&lt;/p&gt;

&lt;p&gt;So, does an icon need an alt attribute? Well, it depends on how the icon is being added to the page and what the purpose of that icon is.&lt;/p&gt;

&lt;p&gt;If an icon is added using an inline image element, it &lt;em&gt;must&lt;/em&gt; have an alt attribute. The value of that alt attribute can be a string of text (&lt;code&gt;&amp;lt;img src="icon.png" alt="Get more information" /&amp;gt;&lt;/code&gt;) or an empty value (&lt;code&gt;&amp;lt;img src="icon.png" alt="" /&amp;gt;&lt;/code&gt;) in case it’s a decorative icon, but it absolutely must have an alt attribute.&lt;/p&gt;

&lt;p&gt;If the icon is added through CSS, it will never actually have an “alt attribute” as alt attributes are used on an &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; element. The icon can still, however, have a text alternative or a text equivalent to provide context for users.&lt;/p&gt;

&lt;p&gt;An icon added through CSS for purely decorative purpose, for example, a fancy bullet list icon, doesn’t need any text alternative to provide more context or information to the user.&lt;/p&gt;

&lt;p&gt;On the other hand, a when an icon added through CSS is functional (e.g. a magnifying lens to activate search) or provides some sort of information to the user (e.g. a check mark or an x to depict which features are included in a product), you need to include a text alternative. The text alternative in this case is not added through an &lt;code&gt;alt&lt;/code&gt; attribute. It could just be a contextual text either accompanying the icon on the page or it could be a visually hidden string made available to screen reader users.&lt;/p&gt;

&lt;p&gt;But, why do you need any alt text at all on icons? Because icons on their own may not be enough to give users context. For example, when you create an icon button for a hamburger menu or search, screen reader users with no or low vision will have no idea what that button does when they land on it unless there is some text there to tell them the purpose of that button. &lt;/p&gt;

&lt;p&gt;Screen reader users aren't the only people who need accessible icons. Most icons and symbols without any accompanying text can be just as confusing for persons with cognitive disabilities or someone who lacks the cultural context. Including text alternatives or alt text to your images is one of the simplest and quickest way of making your website usable and accessible.&lt;/p&gt;

&lt;p&gt;And finally, if you’re still not convinced and need one more reason to include appropriate text alternatives for your icons, it's a great SEO win as well. Search engines, such as Google, give pages that include alt text in images high importance when indexing websites. &lt;/p&gt;

&lt;p&gt;--&lt;/p&gt;

&lt;p&gt;Have a question? Feel free to ask in the comments below or on &lt;a href="https://twitter.com/nadiarasul"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
      <category>html</category>
      <category>css</category>
    </item>
    <item>
      <title>4 things I do on every website to make it accessible</title>
      <dc:creator>Nadia Rasul</dc:creator>
      <pubDate>Tue, 25 Feb 2020 02:00:26 +0000</pubDate>
      <link>https://dev.to/nadiarasul/4-things-i-do-on-every-website-to-make-it-accessible-213b</link>
      <guid>https://dev.to/nadiarasul/4-things-i-do-on-every-website-to-make-it-accessible-213b</guid>
      <description>&lt;p&gt;Over the years as a front-end developer, I have picked up a few basics for building accessible websites that have become an integral part of my daily workflow. These techniques give me a solid foundation for building an inclusive website that is welcoming to all, and they help me write cleaner and more performant code.&lt;/p&gt;

&lt;p&gt;Following is a list of some of the things that I do on every website without fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Use semantic HTML markup
&lt;/h2&gt;

&lt;p&gt;Semantic HTML is at the core of creating an accessible website. It takes the DOM tree and turns it into the accessibility tree which helps machines, including assistive technologies and search engines, understand the content and the structure of the page.&lt;/p&gt;

&lt;p&gt;My favorite example is the case of buttons. Using the semantic button element instead of a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; or a &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;, gives you most of the accessibility goodness right out of the box without having to write a lot of extra code.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; gives you things like focus handling, user input handling, form submission, and some basic styling that can be exposed to the accessibility API. On the other hand, using a custom button element means you would need to write additional code, most likely using JavaScript, to make your custom element functional. And, you will have to include additional attributes in the markup such as &lt;code&gt;role&lt;/code&gt; and &lt;code&gt;tabindex&lt;/code&gt; to make it accessible for keyboard and screen reader users.&lt;/p&gt;

&lt;p&gt;Take a look at this div marked up as a button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; 
 &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; 
 &lt;span class="na"&gt;role=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; 
 &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"runThatFunc()"&lt;/span&gt;
 &lt;span class="na"&gt;onkeydown=&lt;/span&gt;&lt;span class="s"&gt;"runThatFunc()"&lt;/span&gt;
 &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
 Submit 
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this example, you need to add the &lt;code&gt;role&lt;/code&gt;, &lt;code&gt;tabindex&lt;/code&gt;, and a keydown event to make sure that div is going to behave like an accessible button.&lt;/p&gt;

&lt;p&gt;Now consider a semantic button element:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; 
 &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; 
 &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"runThatFunc()"&lt;/span&gt;
&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
 Submit 
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When you use an actual &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;, all you need to do is attach a function that will do a thing when someone interacts with this button and you’re done. That’s three less things you need to worry about to make it act like an accessible button that will work equally well with a keyboard and a mouse.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Create a logical heading structure
&lt;/h2&gt;

&lt;p&gt;Headings can be an important navigational tool for users of assistive technology. According to &lt;a href="https://webaim.org/projects/screenreadersurvey8"&gt;WebAIM’s Screen Reader Survey for 2018&lt;/a&gt;, nearly 70% of people use headings to navigate content and over 52% of the people find heading levels useful for finding information on the page. Just as visual users can quickly scan the page to understand the hierarchy of the content by looking at the headings, screen readers allow users can listen to a list of headings on a page and start reading from one they are interested in.&lt;/p&gt;

&lt;p&gt;There should be at least one &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; per page to convey the overall purpose of the page followed by &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; to &lt;code&gt;&amp;lt;h6&amp;gt;&lt;/code&gt; in a sequential order. New sections can begin with headings of equal or higher rank, and within each section headings of smaller rank can be used for starting subsections.&lt;/p&gt;

&lt;p&gt;Avoid skipping heading levels within a section as the resulting content flow can be confusing for a user navigating by headings. This means, an &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; should never be followed directly by an &lt;code&gt;&amp;lt;h5&amp;gt;&lt;/code&gt;. However, you can use an &lt;code&gt;&amp;lt;h2&amp;gt;&lt;/code&gt; to start a new section after an &lt;code&gt;&amp;lt;h4&amp;gt;&lt;/code&gt; has been used in the previous section.&lt;/p&gt;

&lt;p&gt;Finally, a heading element should never be used just for stylistic purposes. There’s CSS for that! If the content doesn’t make sense as a headline, it should not be contained in a heading tag.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Include text alternatives for images
&lt;/h2&gt;

&lt;p&gt;The internet is full of images that make it a rich and exciting place, and sometimes also provide functional information. It can be very frustrating for some users if they land on a page and are unable to see or hear some parts of it, especially if that information is needed to perform an action on the site.&lt;/p&gt;

&lt;p&gt;Including useful text alternatives on images can let users with low or no vision understand the content better. Every image must include an alt attribute with a description of exactly what the image is representing. Screen readers announce images as images, so your alt text does not need to start with “Picture of ” or “Image of” as that would be redundant information.&lt;/p&gt;

&lt;p&gt;In case of decorative images that do not contain any valuable information for the users to understand the content, an empty alt text (&lt;code&gt;alt=“”&lt;/code&gt;) can be used. However, an alt attribute must always be present even if the value is null.&lt;/p&gt;

&lt;p&gt;Any functional or informative images such as social media icons, accepted credit card logos, help icon, search icon etc. must have text alternatives that describe the purpose of the icon.&lt;/p&gt;

&lt;p&gt;If the icon is included as an image within a link, you can use the text of the link to convey the purpose along with an empty alt text on the image.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"website.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
 &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"logo.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
 Website Name 
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Or, you can use the alt text on the image to let the user know where the link goes if no visual link text is used.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"website.com"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
 &lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"logo.jpg"&lt;/span&gt; &lt;span class="na"&gt;alt=&lt;/span&gt;&lt;span class="s"&gt;"Website Name"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Got text within an image? Scrap it! Images with text within them are problematic for screen reader users as assistive technologies would not be able to read that text. If you can, include that text as part of the content on the page. However, if the image of text is unavoidable, then that exact text should be included as alt text on the image.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Label form fields
&lt;/h2&gt;

&lt;p&gt;Labels help identify a field for screen reader users when they are interacting with it. Use the &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; element to label your form fields and programmatically connect it to the form control using the for attribute.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Email address:&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You might think that using a placeholder instead of a label is sufficient as it provides a visual cue for what information is requested. However, placeholder text can be problematic for both visual and non-visual users. The placeholder text disappears when a user starts typing in the field and even visual users can sometimes have trouble identifying the purpose of the input if no label is present.&lt;/p&gt;

&lt;p&gt;In addition, screen reader users can find it frustrating as the placeholder attribute does not always get announced because of inconsistent support across browsers and screen readers.&lt;/p&gt;

&lt;p&gt;If a field has been designed without visible labels and for whatever reason there is no way you can have that changed in design, the markup should still include a visually hidden label that is associated with the field.&lt;/p&gt;

&lt;p&gt;There are a lots of different ways for visually hiding elements on a page using CSS, however not all of those ways are equally accessible. If you want your content to be visually hidden, but still available to screen reader users, you have to be careful not to use &lt;code&gt;display: none;&lt;/code&gt; or &lt;code&gt;visibility: hidden;&lt;/code&gt; as both those properties will hide the content from screen readers. Instead, you can hide the content only for visual users by using the clip property in CSS.&lt;/p&gt;

&lt;p&gt;Here is a snippet that will cover most of the basic scenarios where you might need to make an element only available for screen reader users:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.show-for-sr&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt; &lt;span class="cp"&gt;!important&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nl"&gt;clip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Form controls that are related, such as a list of checkboxes or radio buttons, should be grouped together with &lt;code&gt;&amp;lt;fieldset&amp;gt;&lt;/code&gt;. They can be given description using the &lt;code&gt;&amp;lt;legend&amp;gt;&lt;/code&gt; element to provide more context for users of assistive technologies. Some screen readers will read out the legend with each choice, so a user doesn’t just hear the option such as “Lightsaber” or “Sonic Screwdriver” in the example below, but they will also hear the question that the option is associated with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;legend&amp;gt;&lt;/span&gt;Choose your weapon:&lt;span class="nt"&gt;&amp;lt;/legend&amp;gt;&lt;/span&gt;    
 &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"lightsaber"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"weapons"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"lightsaber"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lightsaber&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"sonic-screwdriver"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"weapons"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"sonic-screwdriver"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sonic Screwdriver&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"baguette"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"weapons"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"baguette"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Baguette&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you got all the way to the end of this post, thanks for reading! I hope you find these tips useful and will incorporate them in your work.&lt;/p&gt;

&lt;p&gt;Have a question? Feel free to ask in the comments below or on &lt;a href="https://twitter.com/nadiarasul"&gt;twitter&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
