Accessibility Best Practices

Create inclusive applications that meet modern accessibility standards and guidelines.

1. Semantic HTML

Use semantic HTML elements to provide structure and meaning to screen readers and other assistive technologies. Properly defined structure helps users navigate content efficiently.

Example


<header role="banner">
    <h1>Main Heading</h1>
    <nav aria-label="Main navigation">
        <ul>
            <li>Home</li>
            <li>About</li>
        </ul>
    </nav>
</header>
<aside role="complementary">
    <h2>Sidebar Content</h2>
    <p>Supporting information</p>
</aside>

                    

Use role, aria-label and semantic tags to describe content properly.

2. Keyboard Navigation

Ensure all interactive elements are accessible via keyboard for users who cannot use a mouse. Provide visual indication for focusable elements.

Example


<button 
    class="focus:outline-none focus:ring-2 focus:ring-indigo-500">
    Action Button
</button>

                    

Visually style focus states and ensure proper tabindex behavior for all interactive components.

3. Color Contrast

Provide at least 4.5:1 contrast ratio for text with background, and 3:1 for large text. Use color combinations that are friendly for color-blind users.

Example


.text-contrast {
    background-color: #f3f4f6;
    color: #111827; /* #1A1A1A */
}
.high-contrast {
    background-color: #f9fafb;
    color: #03070e;
}

                    

Test with tools like Color Contrast Checker before publishing.

4. ARIA Implementation

Use ARIA attributes appropriately to enhance accessibility for complex UI components. Ensure all roles and properties are correctly implemented and validated.

Example


<button 
    aria-controls="modal-1"
    aria-expanded="false"
    type="button">
    Show Details
</button>

<div role="dialog" 
     aria-labelledby="modal-title"
     tabindex="-1"
     class="modal" id="modal-1">
    <div class="modal-content">
        <span id="modal-title" class="sr-only">Modal Title</span>
        <p>Accessible modal content</p>
    </div>
</div>
                    
                

Always pair ARIA attributes with visual design indicators and avoid using ARIA as a band-aid fix. Use role="dialog", aria-hidden, and aria-describedby as needed.

Test Your Accessibility Knowledge

Fix the accessibility issues in the code below to make it accessible for screen readers.


<div>
    <button>Main Action</button>
</div>
                
                
Try Challenge