{"id":127,"date":"2022-01-07T12:49:07","date_gmt":"2022-01-07T10:49:07","guid":{"rendered":"https:\/\/www.accessi.org\/blog\/?p=127"},"modified":"2022-12-28T13:08:01","modified_gmt":"2022-12-28T11:08:01","slug":"must-haves-for-web-accessible-html-in-your-site","status":"publish","type":"post","link":"https:\/\/www.accessi.org\/blog\/must-haves-for-web-accessible-html-in-your-site\/","title":{"rendered":"Must-Haves for Web Accessible HTML in Your Site\u00a0"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Technical writing is fast becoming a side hustle for web developers the world over. As <a title=\"Offer for Developers\" href=\"https:\/\/www.accessi.org\/developers\">developers<\/a>, you should lead by example. So I\u2019ve curated a list of accessibility practices that are essential for any HTML website. But first, what is web accessibility?<\/span><\/p>\n<p><a href=\"https:\/\/www.w3.org\/WAI\/fundamentals\/accessibility-intro\/\"><span style=\"font-weight: 400;\">Web accessibility<\/span><\/a><span style=\"font-weight: 400;\"> (a11y) is the practice of building digital products in a way that is accessible to people with disabilities \u2014 such products usually conform to the Web Content Accessibility Guidelines (WCAG).<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Semantic HTML<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Semantics in web design describes writing meaningful HTML code using self-expressive tags that make sense to both the developer and the browser engine which renders the a11y tree. When an element is semantically accurate, screen readers are able to announce its role name state, and value.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There\u2019s a simple concept that I\u2019d like to mention in relation to semantics and that\u2019s affordance. The implicit design of things can give users a clue on how to use them. For example, a doorknob suggests to anyone approaching a door that it may be opened by turning the knob. In web apps, affordances are important to help to make the UX hitch-free. A good example is a hamburger menu icon (the 3 horizontal dashes usually at the top corner of a web page) which suggests to the user that there is a hidden menu that can be accessed by clicking.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Good semantics involves intuitive design experience and affordances are the way to achieve that.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">ARIA<\/span><\/h2>\n<p><a href=\"https:\/\/www.w3.org\/WAI\/PF\/aria-1.1\/states_and_properties\"><span style=\"font-weight: 400;\">ARIA<\/span><\/a><span style=\"font-weight: 400;\"> is an acronym for accessible rich internet applications. These applications are attributes that communicate with the accessibility tree of a subset of the DOM. This simplified rendering of a website is the accessibility tree. This is sometimes called the &#8220;shadow DOM&#8221;. This version can be read by screen readers and is focusable by keyboards.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">ARIA enables developers to express a broad range of HTML semantic concepts via the use of HTML attributes. It extends the use case of HTML elements beyond that which current semantic HTML tags allow. By assigning the correct role property to an HTML tag, ARIA is able to perform its intended function. However, we should not define roles with abstract terms. The DOM and accessibility tree are structured with a few different types of roles. Here are a few examples:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Landmarks<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Navigation<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Search<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Banner<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Main<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Widgets<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">menuitem<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">tab<\/span><\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.w3.org\/WAI\/PF\/aria-1.1\/roles\"><span style=\"font-weight: 400;\">The Roles Model by W3<\/span><\/a><span style=\"font-weight: 400;\"> provides an alphabetical listing of all ARIA roles along with their definitions in section 5.4.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ways in which ARIA can affect the a11y tree include:<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Role-playing<\/strong>. This represents a shorthand for a particular UI pattern. E.g the checkbox pattern that has states of &#8220;checked&#8221; and &#8220;unchecked&#8221;.<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Express semantic relationships between elements<\/strong>. For instance what button controls what functionality, or to present a child menu as a child of a parent menu using the &#8220;aria-owns&#8221; attribute, aria-activedescendant, aria-describedby, aria-posinset, or aria-setsize attributes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, using aria-describedby property to describe a Close button&#8217;s action. A button with the same purpose as a &#8216;close&#8217; button is described elsewhere in the document. In order to associate the description with the link, we use the aria-describedby property.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&lt;button aria-label=&#8221;Close&#8221; aria-describedby=&#8221;descriptionClose&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0\u00a0\u00a0\u00a0onclick=&#8221;myDialog.close()&#8221;&gt;X&lt;\/button&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&#8230;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&lt;div id=&#8221;descriptionClose&#8221;&gt;Closing this window will discard any information entered and<\/span><\/p>\n<p><span style=\"font-weight: 400;\">return you back to the main page&lt;\/div&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Live updates.<\/strong> Using aria-live attribute: This Informs assistive technology right away when there&#8217;s a change in the status of the page such as a message in a chat box.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Media with Lazy Loading<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Google Chrome has a native feature called lazy loading. The feature prevents images from being loaded until they are actually viewed. It&#8217;s awesome because images and videos won&#8217;t pre-load and slow down the page. To use the lazy loading feature, add the following code to the image HTML tags:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">loading=&#8221;lazy&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There is Javascript that adds cross-browser support. To learn more about lazy loading for other browsers, check out this article by Addy Osmani.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Tab Index<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">There are some web users who only use their keyboards to navigate websites. Up and down arrows scroll, the tab key focuses on links, buttons, and selectable page elements and the enter key selects. Most modern browsers feature keyboard focus. You can use tabindex when a web browser cannot detect the portions of a website that should be clicked or hovered over. A tabindex organizes selectable items on a page into a hierarchy. Its default value is 0. As a result, everything is equally important and will be sorted from left to right for rows, then up and down for side menus or columns. To ensure easy navigation, change the tab index to match the layout of the page.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Alt Text<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In HTML, ALT text is the <\/span><a href=\"https:\/\/www.accessi.org\/blog\/how-to-add-an-alt-attribute-to-an-image\/\"><span style=\"font-weight: 400;\">alternative text description<\/span><\/a><span style=\"font-weight: 400;\"> given to an image that explains what the image is about. There are various reasons for adding alt text to images. It is recommended by the WCAG and it provides an alternative description for people who are blind and people with low bandwidth.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The alternative text is not visible to the user, but holds information about its link or image. It can be a description or an attribute. It is available to screen readers and search engines to index images and links.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here is an example of how best to insert an image using HTML\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">&lt;img src=\u201cimage.jpg\u201d width=\u201c500px\u201d height=\u201c600px\u201d alt=\u201cimage description\u201d title=\u201cimage tooltip\u201d&gt;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The alt attribute describes the image, and the title attribute provides a tooltip that appears when a user hovers over the image.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As developers, you should lead by example. So I\u2019ve curated a list of accessibility practices that are essential for any HTML website.<\/p>\n","protected":false},"author":2,"featured_media":128,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/posts\/127"}],"collection":[{"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/comments?post=127"}],"version-history":[{"count":2,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":363,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/posts\/127\/revisions\/363"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/media\/128"}],"wp:attachment":[{"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/media?parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/categories?post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/tags?post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}