Foundation - Button Accessibility



Description

When your button does not contain readable text, you can add screen reader-only text to tell its purpose. The symbol or icon must be placed in an element with aria-hidden-"true" attribute, which avoids the screen readers from attempting to pronounce the icon or symbol. To define screen readers-only text use .show-for-sr class.

Example

The following example demonstrates the use of button accessibility in Foundation.

<html>
   <head>
      <title>Button Accessibility</title>

      <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/css/foundation.min.css" integrity="sha256-1mcRjtAxlSjp6XJBgrBeeCORfBp/ppyX4tsvpQVCcpA= sha384-b5S5X654rX3Wo6z5/hnQ4GBmKuIJKMPwrJXn52ypjztlnDK2w9+9hSMBz/asy9Gw sha512-M1VveR2JGzpgWHb0elGqPTltHK3xbvu3Brgjfg4cg5ZNtyyApxw/45yHYsZ/rCVbfoO5MSZxB241wWq642jLtA==" crossorigin="anonymous">
      <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/foundicons/3.0.0/foundation-icons.css">

      <!-- Compressed JavaScript -->
      <script src="https://cdn.jsdelivr.net/npm/foundation-sites@6.5.1/dist/js/foundation.min.js" integrity="sha256-WUKHnLrIrx8dew//IpSEmPN/NT3DGAEmIePQYIEJLLs= sha384-53StQWuVbn6figscdDC3xV00aYCPEz3srBdV/QGSXw3f19og3Tq2wTRe0vJqRTEO sha512-X9O+2f1ty1rzBJOC8AXBnuNUdyJg0m8xMKmbt9I3Vu/UOWmSg5zG+dtnje4wAZrKtkopz/PEDClHZ1LXx5IeOw==" crossorigin="anonymous"></script>


   </head>

   <body>
      <p>When he reached
         <button class = "button" type = "button">
            <span class = "show-for-sr">home</span>
            <!-- Screen readers will see "home" but Visual users will see the home icon, but not the "home" text -->
            <span aria-hidden = "true"><i class = "fi-home"></i></span>
         </button> the children were playing.
      </p>

      <p>Copy and paste the above sentence to see what it is.</p>
   </body>
</html>

Output

Let us carry out the following steps to see how the above given code works −

  • Save the above given html code button_accessibility.html file.

  • Open this HTML file in a browser, an output is displayed as shown below.

foundation_basic_controls.htm
Advertisements