{"id":186,"date":"2022-05-23T09:03:56","date_gmt":"2022-05-23T06:03:56","guid":{"rendered":"https:\/\/www.accessi.org\/blog\/?p=186"},"modified":"2022-05-23T14:31:39","modified_gmt":"2022-05-23T11:31:39","slug":"wcag-checklist-with-code-examples","status":"publish","type":"post","link":"https:\/\/www.accessi.org\/blog\/wcag-checklist-with-code-examples\/","title":{"rendered":"WCAG 2.1 Checklist with Code Examples"},"content":{"rendered":"<p>The WCAG checklist is a list of criteria that ensure web content and websites are accessible for all users.<\/p>\n<p>This article will cover several WCAG guidelines with useful code snippets for each guideline.<\/p>\n<h2>WCAG 2.1 LEVEL A CHECKPOINTS<\/h2>\n<h3>Principle 1: Perceivable<\/h3>\n<p>Information and user interface components must be presentable to users in ways they can perceive.<\/p>\n<p><a title=\"Understanding Success Criterion 1.1.1: Non-text Content\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/non-text-content.html\" target=\"_blank\" rel=\"noopener nofollow\">1.1. Text Alternatives<\/a><br \/>\nAll non-text content such as images, icons, charts, etc must have alternative text that describes the content.<\/p>\n<p>No alt attribute has been added to this image.<\/p>\n<pre>\/\/bad code\r\n\r\n&lt;img src=\"logo.png\" \/&gt;<\/pre>\n<p>An ait attribute has been added.<\/p>\n<pre>\/\/good code\r\n\r\n&lt;img src=\"logo.png\" alt=\"company's logo\" \/&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 1.3.1: Info and Relationships\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/info-and-relationships.html\" target=\"_blank\" rel=\"noopener nofollow\">1.3.1 Info and Relationships<\/a><br \/>\nInformation, structure, and relationships conveyed through presentation can be programmatically determined or are available in text.<\/p>\n<p>A good example is adding proper semantic meaning and emphasis to text content.<\/p>\n<p>Styling the text to appear bold may work for sighted users. However, screen readers will be unable to emphasize the text for visually impaired users.<\/p>\n<pre>\/\/bad code\r\n\r\n&lt;p&gt;Get out of bed &lt;span&gt;now&lt;\/span&gt;!&lt;\/p&gt;\r\n\r\nspan {\r\n  font-weight: bold;\r\n}\r\n<\/pre>\n<p>Using the appropriate elements gives semantic meaning to the text and fixes this issue.<\/p>\n<pre>\/\/good code\r\n\r\nGet out of bed &lt;em&gt;now&lt;\/em&gt;!\r\n<\/pre>\n<h3>Principle 2: Operable<\/h3>\n<p>User interface components and navigation must be operable.<\/p>\n<p><a title=\"Success Criterion 2.1.1 Keyboard\" href=\"https:\/\/www.w3.org\/TR\/WCAG21\/#keyboard\" target=\"_blank\" rel=\"noopener nofollow\">2.1.1 Keyboard<\/a><br \/>\nAll functionality should be operable with a keyboard.<\/p>\n<p>This div can be styled to appear like a button. However, it will not have semantic meaning or keyboard focus.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;div class=\"button\"&gt;submit&lt;\/div&gt;\r\n<\/pre>\n<p>A simple solution is to use a button element.<\/p>\n<pre>\/\/good code\r\n\r\n&lt;button&gt;submit&lt;\/button&gt;\r\n<\/pre>\n<p>If for some reason a div has to be used, adding a role and tabindex will make it keyboard operable.<\/p>\n<pre>&lt;div role=\"button\" tabindex=\"0\"&gt;Close&lt;\/div&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 2.4.2: Page Titled\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/page-titled.html\" target=\"_blank\" rel=\"noopener nofollow\">2.4.2 Page titled<\/a><br \/>\nTitles of the page should describe the topic or purpose.<\/p>\n<p>The title of the page is not clear from this heading.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;h1&gt;a website's page&lt;\/h1&gt;\r\n<\/pre>\n<p>The title of the page is clear from this heading.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;h1&gt;About Us&lt;\/h1&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 2.4.4: Link Purpose (In Context)\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/link-purpose-in-context\" target=\"_blank\" rel=\"noopener nofollow\">2.4.4 Link Purpose (in context)<\/a><br \/>\nThe target or purpose of the link must be clear by the link text alone, its associated content, or its surrounding content.<\/p>\n<p>The text does not properly describe the purpose of the link.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;a href=\"google.com\"&gt;this is a link to a webpage&lt;\/a&gt;\r\n<\/pre>\n<p>The text clearly describes the purpose of the link.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;a href=\"google.com\"&gt;Go to Google&lt;\/a&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 2.5.3: Label in Name\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/label-in-name.html\" target=\"_blank\" rel=\"noopener nofollow\">2.5.3 Label in Name<\/a><br \/>\nFor user interface components with labels that include text or images of text, the name contains the text that is presented visually.<\/p>\n<p>A speech input user would say \u2018buy\u2019, but the speech software won\u2019t know what item to add.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;button&gt;buy&lt;\/button&gt;\r\n<\/pre>\n<p>To solve this issue, make the label and the accessible name the same.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;button aria-label=\"buy shoes\"&gt;buy shoes&lt;\/button&gt;\r\n<\/pre>\n<h3>Principle 3: Understandable<\/h3>\n<p>Information and the operation of the user interface must be understandable.<\/p>\n<p><a title=\"Understanding Success Criterion 3.1.1: Language of Page\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/language-of-page\" target=\"_blank\" rel=\"noopener nofollow\">3.1.1 Language of Page<\/a><br \/>\nProgrammatically define the primary language of each page.<\/p>\n<p>The lang attribute sets the language for a page.<\/p>\n<pre>&lt;html lang=\"en\"&gt;&lt;\/html&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 3.3.2: Labels or Instructions\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/labels-or-instructions.html\" target=\"_blank\" rel=\"noopener nofollow\">3.3.2 Labels or Instructions<\/a><br \/>\nForm inputs should have labels associated with them.<\/p>\n<p>Form fields without labels associated with them are inaccessible.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;input name=\"userEmail\" type=\"email\" \/&gt;\r\n<\/pre>\n<p>Associating form fields with labels gives users a larger clickable area. Labels also help users to fill in the correct information in the form field.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;label for=\"email\"&gt;Enter your email address&lt;\/label&gt;\r\n&lt;input id=\"email\" name=\"userEmail\" type=\"email\" \/&gt;\r\n<\/pre>\n<h3>Principle 4: Robust<\/h3>\n<p>Content must be robust enough that it can be interpreted by a wide variety of user agents, including assistive technologies.<\/p>\n<p><a title=\"Understanding Success Criterion 4.1.1: Parsing\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/parsing.html\" target=\"_blank\" rel=\"noopener nofollow\">4.1.1 Parsing<\/a><br \/>\nMake sure that the following are taken care of in the markup<\/p>\n<p>&#8211; Elements should have unique IDs.<\/p>\n<p>The IDs are similar; this is wrong.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;button id=\"button\"&gt;submit&lt;\/button&gt;\r\n&lt;button id=\"button\"&gt;login&lt;\/button&gt;\r\n<\/pre>\n<p>The IDs are distinct; this is correct.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;button id=\"submit\"&gt;submit&lt;\/button&gt;\r\n&lt;button id=\"login\"&gt;login&lt;\/button&gt;\r\n<\/pre>\n<p>&#8211; Elements have proper opening and closing tags.<\/p>\n<p>There is no closing tag.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;button&gt;submit\r\n&lt;\/button&gt;\r\n<\/pre>\n<p>There is a closing tag.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;button&gt;submit&lt;\/button&gt; \r\n<\/pre>\n<p>&#8211; Elements are properly nested.<\/p>\n<p>Block-level elements should not be nested in inline elements.<\/p>\n<pre>\/\/bad code\r\n\r\n&lt;p&gt;\r\n&lt;div&gt;i am a block level element nested in an inline element. This is wrong&lt;\/div&gt;\r\n&lt;\/p&gt;\r\n<\/pre>\n<p>Inline elements can be nested in block-level elements.<\/p>\n<pre>\/\/good code\r\n\r\n&lt;div&gt;\r\n&lt;p&gt;i am an inline element nested in a block level element. This is right.&lt;\/p&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 4.1.2: Name, Role, Value\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/name-role-value.html\" target=\"_blank\" rel=\"noopener nofollow\">4.1.2 Name, Role, Value<\/a><br \/>\nAll interactive elements on a page should have a name and role, state. and value where applicable.<\/p>\n<p>An image of a button was used instead of a button element.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;img src=\"button.png\" alt=\"click the button\" \/&gt;\r\n<\/pre>\n<p>A button element was used.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;input name=\"form submission button\" type=\"submit\" value=\"submit the form\" \/&gt;\r\n<\/pre>\n<h2>WCAG 2.1 LEVEL AA CHECKPOINTS<\/h2>\n<h3>Principle 1: Perceivable<\/h3>\n<p><a title=\"Understanding Success Criterion 1.3.4: Orientation\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/orientation.html\" target=\"_blank\" rel=\"noopener nofollow\">1.3.4 Orientation<\/a><br \/>\nContent adapts to different screen sizes and display orientation.<\/p>\n<p>By setting the width of the card to 500px, it will overflow on mobile phones and small screens.<\/p>\n<pre>    \r\n\/\/bad code \r\n\r\n    .card {\r\n      width: 500px;\r\n    }\r\n<\/pre>\n<p>Changing the height to 500px with media queries ensures that the content adapts.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n    .card {\r\n      width: 100%;\r\n    }\r\n    @media screen and (min-width: 768px) {\r\n      .card {\r\n        width: 500px;\r\n      }\r\n    }\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 1.3.5: Identify Input Purpose\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/identify-input-purpose.html\" target=\"_blank\" rel=\"noopener nofollow\">1.3.5 Identify Input Purpose<\/a><br \/>\nThe purpose of input fields should be programmatically determinable.<\/p>\n<p>The type attribute was not added to the input element.<\/p>\n<pre>    \r\n\/\/bad code  \r\n\r\n&lt;input name=\"userEmail\" type=\"text\" placeholder=\"enter your email address\" \/&gt;\r\n<\/pre>\n<p>Setting the type attribute to `email` helps assistive technologies know what type of data is required. This enables them to automatically fill out the form for users.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;input name=\"userEmail\" type=\"email\" placeholder=\"enter your email address\" \/&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 1.4.4: Resize text\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/resize-text.html\" target=\"_blank\" rel=\"noopener nofollow\">1.4.4 Resize text<\/a><br \/>\nText content should remain readable even when users zoom up to 200%.<\/p>\n<p>With these static styles, when a user zooms in, the static sizing will affect the readability of the text.<\/p>\n<pre>    \r\n\/\/bad code   \r\n\r\n    .card-static-units {\r\n      height: 200px;\r\n      width: 400px;\r\n    }\r\n<\/pre>\n<p>Using scalable sizing units fixes this issue.<\/p>\n<pre>    \r\n\/\/good code \r\n\r\n    .card-dynamic-units {\r\n      height: 12.5rem;\r\n      width: 25rem;\r\n    }\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 1.4.5: Images of Text\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/images-of-text.html\" target=\"_blank\" rel=\"noopener nofollow\">1.4.5 Images of text<\/a><br \/>\nUse real text as much as possible instead of images of text.<\/p>\n<p>Screen readers will be unable to read text on images.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n    &lt;img src=\"page heading\" \/&gt;\r\n<\/pre>\n<p>Therefore, text content must be presented in a proper and accessible format.<\/p>\n<pre>    \r\n\/\/good code&lt;\/pre&gt;\r\n&lt;h1&gt;Page Heading&lt;\/h1&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 1.4.10: Reflow\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/reflow.html\" target=\"_blank\" rel=\"noopener nofollow\">1.4.10. Reflow<\/a><br \/>\nContent can be presented without loss of information or functionality, and without requiring<br \/>\nscrolling in two dimensions.<\/p>\n<p>This style will cause horizontal scroll on small screens.<\/p>\n<pre>    \r\n\/\/bad code    \r\n\r\n    .card {\r\n      width: 500px;\r\n    }\r\n<\/pre>\n<p>Using responsive CSS fixes the issue.<\/p>\n<pre>    \r\n\/\/good code  \r\n \r\n    .card {\r\n      width: 100%;\r\n    }\r\n    @media screen and (min-width: 768px) {\r\n      .card {\r\n        width: 500px;\r\n      }\r\n    }\r\n<\/pre>\n<h3>Principle 2: Operable<\/h3>\n<p><a title=\"Understanding SC 2.4.6 Headings and Labels\" href=\"https:\/\/www.digitala11y.com\/headings-labels-understanding-sc-2-4-6\/\" target=\"_blank\" rel=\"noopener nofollow\">2.4.6 Headings and Labels<\/a><br \/>\nHeadings and labels should be descriptive.<\/p>\n<p>A bad example of a descriptive heading.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;h1&gt;Intro&lt;\/h1&gt;\r\n<\/pre>\n<p>A good example of a descriptive heading.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;h1&gt;Introduction to Accessibility&lt;\/h1&gt;\r\n<\/pre>\n<p>A bad example of a descriptive label.<\/p>\n<pre>    \r\n\/\/bad code\r\n\r\n&lt;label&gt;fill form&lt;\/label&gt;\r\n&lt;input type=\"text\" \/&gt;\r\n<\/pre>\n<p>A good example of a descriptive label.<\/p>\n<pre>    \r\n\/\/good code\r\n\r\n&lt;label&gt;Name&lt;\/label&gt;\r\n&lt;input name=\"name\" type=\"text\" \/&gt;\r\n<\/pre>\n<p><a title=\"Understanding Success Criterion 2.4.7: Focus Visible\" href=\"https:\/\/www.w3.org\/WAI\/WCAG21\/Understanding\/focus-visible.html\" target=\"_blank\" rel=\"noopener nofollow\">2.4.7 Focus Visible <\/a><br \/>\nProvide a clearly visible focus indicator for all the interactive elements.<\/p>\n<p>When the link is in focus, it will have a red border on it.<\/p>\n<pre>a:focus{\r\n    border: 1px solid red\r\n    }\r\n<\/pre>\n<h3>Principle 3: Understandable<\/h3>\n<p>3.1.2 Language of parts<br \/>\nIf any text or element on the web page has a different language than the primary language, programmatically define the language for that content.<\/p>\n<pre>&lt;html lang=\"en\"&gt;\r\n  &lt;body&gt;\r\n    &lt;p lang=\"fr\"&gt;I have a different language, French!&lt;\/p&gt;\r\n  &lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The WCAG 2.1 checklist is a list of criteria ensuring web content and websites are accessible for all users. We cover several guidelines with code snippets.  <\/p>\n","protected":false},"author":2,"featured_media":200,"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\/186"}],"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=186"}],"version-history":[{"count":41,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/posts\/186\/revisions\/242"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/media\/200"}],"wp:attachment":[{"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.accessi.org\/blog\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}