Back to Blog
January 14, 20268 min readCreating Accessible UI

Creating Accessible UI Components from Scratch with AI

R
Replay Team
Developer Advocates

TL;DR: Generate fully accessible UI components directly from screen recordings using Replay's behavior-driven reconstruction engine, saving development time and ensuring inclusivity.

Creating accessible UI is often an afterthought, leading to significant rework and exclusion of users with disabilities. But what if you could start with accessibility baked in, generated directly from a video of intended user behavior? This is the power of AI-driven UI generation, specifically using Replay.

The Accessibility Bottleneck#

Traditional UI development often follows a pattern: build the interface, then test for accessibility. This approach is inherently inefficient. Remediation is costly and time-consuming. Moreover, it often results in a UI that meets accessibility standards but doesn't truly embrace inclusive design principles.

Consider the manual effort involved in ensuring proper ARIA attributes, keyboard navigation, and screen reader compatibility. It's a tedious process, prone to errors, and requires specialized expertise.

Behavior-Driven Reconstruction: Video as the Source of Truth#

Replay offers a radically different approach: behavior-driven reconstruction. Instead of relying on static screenshots or design mockups, Replay analyzes video recordings of user interactions. This allows the AI to understand the intent behind each action, generating code that naturally reflects accessible design principles.

Here's how it works:

  1. Record: Capture a video of yourself interacting with a desired UI component or flow. This video becomes the "source of truth" for Replay.
  2. Analyze: Replay's AI engine, powered by Gemini, analyzes the video, identifying UI elements, user actions (clicks, hovers, keyboard input), and underlying intent.
  3. Reconstruct: Replay generates clean, functional, and accessible code for the UI component or flow. This includes appropriate ARIA attributes, semantic HTML, and keyboard navigation support.

This approach addresses the accessibility bottleneck by integrating it into the initial code generation phase.

Replay vs. Traditional Methods#

Let's compare Replay to traditional UI development and screenshot-to-code tools:

FeatureTraditional UI DevelopmentScreenshot-to-CodeReplay
Accessibility FocusOften an afterthoughtLimitedBuilt-in
InputDesign mockups, specificationsStatic imagesVideo of user interaction
Behavior AnalysisManual interpretationNone
ARIA Attribute GenerationManualMinimalAutomatic, context-aware
Keyboard NavigationManual implementationLimitedAutomatic
Understanding User IntentRelies on developer interpretationNoneDeep learning-based analysis
Multi-Page FlowsRequires manual stitchingLimitedSeamless generation

As you can see, Replay offers a significant advantage in creating accessible UI. By analyzing video, it understands the intended user behavior and generates code that reflects that intent.

Building an Accessible Button with Replay#

Let's illustrate this with a practical example: creating an accessible button component.

  1. Record a Video: Record yourself interacting with a button. Show the different states: hover, focus, click, and disabled. Emphasize keyboard navigation by using the Tab key to focus on the button and the Enter key to click it. Narrate your actions: "Now I'm hovering over the button... Now I'm using the Tab key to focus on the button... Now I'm pressing Enter to activate it..."
  2. Upload to Replay: Upload the video to Replay.
  3. Generate Code: Replay analyzes the video and generates the following code (example in React):
typescript
// Generated by Replay import React, { useState } from 'react'; interface ButtonProps { children: React.ReactNode; onClick: () => void; disabled?: boolean; } const AccessibleButton: React.FC<ButtonProps> = ({ children, onClick, disabled }) => { const [isFocused, setIsFocused] = useState(false); const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter' || event.key === ' ') { onClick(); } }; return ( <button onClick={onClick} disabled={disabled} aria-disabled={disabled} onFocus={() => setIsFocused(true)} onBlur={() => setIsFocused(false)} onKeyDown={handleKeyDown} style={{ padding: '10px 20px', backgroundColor: disabled ? '#ccc' : '#007bff', color: 'white', border: 'none', borderRadius: '5px', cursor: disabled ? 'not-allowed' : 'pointer', opacity: disabled ? 0.5 : 1, outline: isFocused ? '2px solid #000' : 'none', // Visible focus indicator }} > {children} </button> ); }; export default AccessibleButton;

This generated code includes several key accessibility features:

  • text
    aria-disabled
    : Indicates the disabled state to screen readers.
  • text
    onFocus
    and
    text
    onBlur
    : Manage the focus state for visual indication.
  • text
    onKeyDown
    : Allows activation with the Enter or Space key.
  • text
    outline
    : Provides a clear visual focus indicator.

💡 Pro Tip: The more detail you provide in your video (explicitly showing keyboard navigation, screen reader usage), the more accurate and accessible the generated code will be.

Advanced Accessibility Features#

Replay's capabilities extend beyond basic ARIA attributes. It can also generate code for:

  • Live Regions: Dynamically update content for screen readers.
  • Custom ARIA Attributes: Implement complex accessibility patterns.
  • Keyboard Traps: Manage focus within modal dialogs.
  • Semantic HTML: Use appropriate HTML5 elements for structure and meaning.

Integrating with Supabase#

Replay seamlessly integrates with Supabase, allowing you to store and manage your generated UI components in a database. This enables collaboration, version control, and easy reuse of accessible components across your projects.

📝 Note: Supabase integration requires setting up your Supabase project and configuring the API keys within Replay. Refer to the Replay documentation for detailed instructions.

Styling and Customization#

Replay allows you to inject custom styles into your generated components, ensuring they seamlessly integrate with your existing design system. You can use CSS-in-JS libraries like Styled Components or Emotion, or simply provide CSS classes.

⚠️ Warning: While Replay generates accessible code, it's crucial to review and test the generated components thoroughly to ensure they meet your specific accessibility requirements. Automated tools are helpful, but human review is still essential.

Step-by-Step Guide: Creating a Multi-Page Accessible Form#

Let's walk through creating a multi-page form with accessibility in mind using Replay.

Step 1: Record the User Flow#

Record a video of you filling out the form, page by page. Make sure to demonstrate tabbing through the form fields, using the keyboard to select options, and handling errors. Speak clearly, describing each action you take. For example, "Now I'm tabbing to the next field... Now I'm selecting an option from the dropdown using the arrow keys...".

Step 2: Upload and Analyze#

Upload the video to Replay. Allow Replay to analyze the video and reconstruct the form structure.

Step 3: Review and Refine#

Review the generated code. Pay close attention to the ARIA attributes, keyboard navigation, and focus management. Make any necessary adjustments to ensure accessibility compliance.

Step 4: Integrate with Supabase#

Connect Replay to your Supabase project and store the generated form components in your database.

Step 5: Implement Error Handling#

Add robust error handling to the form, ensuring that error messages are clear, concise, and accessible to screen readers. Use ARIA live regions to announce error messages dynamically.

typescript
// Example of using ARIA live region for error messages import React, { useState } from 'react'; const MyForm = () => { const [errorMessage, setErrorMessage] = useState(''); const handleSubmit = (event: React.FormEvent) => { event.preventDefault(); // Validate form data const isValid = false; // Replace with actual validation logic if (!isValid) { setErrorMessage('Please correct the errors below.'); } else { setErrorMessage(''); // Submit the form } }; return ( <form onSubmit={handleSubmit}> {errorMessage && ( <div aria-live="polite" role="alert"> {errorMessage} </div> )} {/* Form fields here */} <button type="submit">Submit</button> </form> ); }; export default MyForm;

Product Flow Maps#

Replay automatically generates product flow maps from your videos, providing a visual representation of the user journey. This helps you identify potential accessibility bottlenecks and optimize the user experience.

  • Visualize the user's path through your application.
  • Identify areas where users may encounter accessibility issues.
  • Improve the overall user experience for all users.

Benefits of Using Replay for Accessible UI#

  • Reduced Development Time: Automate the generation of accessible UI components.
  • Improved Accessibility: Ensure accessibility is built in from the start.
  • Enhanced User Experience: Create inclusive and user-friendly interfaces.
  • Cost Savings: Reduce the need for costly accessibility remediation.
  • Increased Collaboration: Share and reuse accessible components across your team.

Frequently Asked Questions#

Is Replay free to use?#

Replay offers a free tier with limited features. Paid plans provide access to advanced features such as Supabase integration, style injection, and multi-page generation. Check the Replay website for the latest pricing information.

How is Replay different from v0.dev?#

While both Replay and v0.dev aim to generate code, Replay distinguishes itself through its video-based approach. v0.dev relies on text prompts, whereas Replay analyzes video of actual user interactions. This allows Replay to understand user intent and generate more accurate and accessible code. Replay's behavior-driven reconstruction, Supabase integration, and style injection features further differentiate it.

What types of videos work best with Replay?#

Clear, well-lit videos with minimal background noise work best. Focus on demonstrating the intended user behavior, including keyboard navigation and screen reader usage. The more detail you provide in your video, the more accurate and accessible the generated code will be.

What frameworks does Replay support?#

Replay currently supports React, with plans to expand to other popular frameworks in the future.

How can I improve the accessibility of the generated code?#

Review and test the generated code thoroughly. Use automated accessibility testing tools and conduct manual testing with assistive technologies. Provide detailed videos that explicitly demonstrate accessible interactions.


Ready to try behavior-driven code generation? Get started with Replay - transform any video into working code in seconds.

Ready to try Replay?

Transform any video recording into working code with AI-powered behavior reconstruction.

Launch Replay Free