Open In App

Tips For Making Coding Websites Accessible

Keeping your website accessible is not as daunting a task as it may seem! Here are a few simple tips you should have in mind while you are coding:

Alternative Text: The alternative text serves two main purposes:






<!DOCTYPE HTML>
<html>
   
<head>
    <meta charset="UTF-8">
    <title>Alt Text</title>
</head>
   
<body>
    <img src=
"gfg.jpg" 
         alt="puppy image" 
         class="image">
</body>
   
</html>

Output:

Title Tag: The <title> tag in HTML is used to define the title of HTML document. It sets the title in the browser toolbar. It provides the title for the web page when it is added to favorites. It displays the title for the page in search engine results.




<!DOCTYPE html>
<html>
  
<head>
    <title>Accessibility in HTML | Home Page</title>
</head>
  
<body>
    <h1>Home Page</h1>
</body>
  
</html>

Output:



Headings: If you are using a heading because you like the font size, stop being lazy and use CSS. Headings play an important role in keeping your website structure accessible. Users that rely on a screen reader to navigate the web can go through a website’s content each heading at a time. The screen reader will go through the headings in order and if you use them correctly, you can make your website more organized and easier to navigate.

Labels: You should use labels to indicate the purpose of certain items on your page.




<!DOCTYPE HTML>
<html>
   
<head>
    <meta charset="UTF-8">
    <title>Labels</title>
</head>
   
<body>
<form aria-label="Go to geeks for geeks home page" 
      action="https://www.geeksforgeeks.org/" 
      target=”_blank”>
    <input type="submit" value="Go to GeeksForGeeks" />
</form>
</body>
   
</html>

Output:

Menus: For a drop-down menu to be accessible, the drop-down items need to stay on the screen. Otherwise, if the user accidentally hovers outside of the drop-down menu, they won’t be able to listen to the items anymore. Use on-click instead of hover to make sure the menu stays on the screen.




<!DOCTYPE html>
<html>
  
<head>
    <meta charset="UTF-8">
    <title>Menu</title>
    <style>
        .dropdown {
            display: inline-block;
            position: relative;
        }
        .dropdown-items {
            display: none;
            position: absolute;
            z-index: 1;
        }
        .dropdown-items a {
            display: block;
        }
        .show {
            display: block;
        }
    </style>
      
    <script>
        function myFunction() {
            document.getElementById("dropdown-menu")
                            .classList.toggle("show");
        }
  
        window.onclick = function(event) {
            if (!event.target.matches('.dropbtn')) {
                var dropdowns = document.
                    getElementsByClassName("dropdown-items");
              
                var i;
                  
                for (i = 0; i < dropdowns.length; i++) {
                    var openDropdown = dropdowns[i];
                      
                    if (openDropdown.classList.contains('show')) {
                        openDropdown.classList.remove('show');
                    }
                }
            }
        }
    </script>
</head>
  
<body>
    <div class="dropdown">
        <button onclick="myFunction()" class="dropbtn">
            Dropdown
        </button>
  
        <div id="dropdown-menu" class="dropdown-items">
            <a href="#">Item 1</a>
            <a href="#">Item 2</a>
            <a href="#">Item 3</a>
        </div>
    </div>
</body>
  
</html>

Output:

TAB key:


Article Tags :