|
| 1 | +Creating a fully-featured screen reader compatibility web app involves a combination of HTML, CSS, and JavaScript, along with proper semantic markup and ARIA (Accessible Rich Internet Applications) attributes. Here's a basic example to get you started: |
| 2 | + |
| 3 | +### HTML (index.html): |
| 4 | + |
| 5 | +```html |
| 6 | +<!DOCTYPE html> |
| 7 | +<html lang="en"> |
| 8 | + <head> |
| 9 | + <meta charset="UTF-8" /> |
| 10 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 11 | + <link rel="stylesheet" href="styles.css" /> |
| 12 | + <title>Screen Reader Compatibility</title> |
| 13 | + </head> |
| 14 | + <body> |
| 15 | + <div id="app"> |
| 16 | + <h1>Screen Reader Compatibility Test</h1> |
| 17 | + <p id="info"> |
| 18 | + This is a simple web app to test screen reader compatibility. |
| 19 | + </p> |
| 20 | + <button id="toggleButton" aria-live="assertive" aria-atomic="true"> |
| 21 | + Toggle Content |
| 22 | + </button> |
| 23 | + <div id="content" aria-hidden="true"> |
| 24 | + <p>This is the content that will be toggled.</p> |
| 25 | + </div> |
| 26 | + </div> |
| 27 | + |
| 28 | + <script src="app.js"></script> |
| 29 | + </body> |
| 30 | +</html> |
| 31 | +``` |
| 32 | + |
| 33 | +### CSS (styles.css): |
| 34 | + |
| 35 | +```css |
| 36 | +body { |
| 37 | + font-family: Arial, sans-serif; |
| 38 | +} |
| 39 | + |
| 40 | +#app { |
| 41 | + max-width: 600px; |
| 42 | + margin: 0 auto; |
| 43 | + padding: 20px; |
| 44 | + text-align: center; |
| 45 | +} |
| 46 | + |
| 47 | +button { |
| 48 | + padding: 10px; |
| 49 | + font-size: 16px; |
| 50 | +} |
| 51 | + |
| 52 | +#content { |
| 53 | + display: none; |
| 54 | + margin-top: 20px; |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +### JavaScript (app.js): |
| 59 | + |
| 60 | +```javascript |
| 61 | +document.addEventListener("DOMContentLoaded", function () { |
| 62 | + const toggleButton = document.getElementById("toggleButton"); |
| 63 | + const content = document.getElementById("content"); |
| 64 | + |
| 65 | + toggleButton.addEventListener("click", function () { |
| 66 | + const isVisible = content.style.display === "block"; |
| 67 | + content.style.display = isVisible ? "none" : "block"; |
| 68 | + const buttonText = isVisible ? "Show Content" : "Hide Content"; |
| 69 | + toggleButton.innerHTML = buttonText; |
| 70 | + |
| 71 | + // Update ARIA attributes |
| 72 | + content.setAttribute("aria-hidden", isVisible ? "true" : "false"); |
| 73 | + toggleButton.setAttribute( |
| 74 | + "aria-expanded", |
| 75 | + isVisible ? "false" : "true" |
| 76 | + ); |
| 77 | + }); |
| 78 | +}); |
| 79 | +``` |
| 80 | + |
| 81 | +In this example: |
| 82 | + |
| 83 | +- A button is provided to toggle the visibility of content. |
| 84 | +- ARIA attributes such as `aria-live`, `aria-atomic`, `aria-hidden`, and `aria-expanded` are used to enhance screen reader compatibility. |
| 85 | +- Proper semantic HTML elements and attributes are used for better accessibility. |
| 86 | + |
| 87 | +This is a basic example, and depending on your specific requirements, you may need to implement more features and enhancements. Additionally, testing with real screen readers like NVDA, JAWS, or VoiceOver is crucial to ensure the compatibility of your web app. |
0 commit comments