Back to Blog
January 6, 20267 min readCreating Dark Mode

Creating Dark Mode UIs with Replay AI and Theme Switching

R
Replay Team
Developer Advocates

TL;DR: Generate a fully functional dark mode UI from a simple screen recording using Replay AI, complete with theme switching functionality.

From Video to Dark Mode: Rebuilding UI with Replay AI#

The holy grail of UI development is speed and accuracy. We need to iterate quickly without sacrificing the user experience. One of the most common UI enhancements is dark mode, but implementing it can be tedious and time-consuming, especially when retrofitting existing applications. Screenshot-to-code tools offer a partial solution, but they often fail to capture the behavior of the UI, leaving you with a static image.

Enter Replay AI, a revolutionary video-to-code engine that understands user behavior and reconstructs working UIs from screen recordings. Replay leverages Gemini to analyze video, understanding not just what the UI looks like, but how it behaves. This "Behavior-Driven Reconstruction" allows for the rapid generation of complex UIs, including those with dynamic features like dark mode.

The Problem with Traditional Approaches#

Implementing dark mode traditionally involves:

  1. Identifying all UI elements that need styling.
  2. Creating separate CSS classes or themes for light and dark modes.
  3. Implementing a mechanism to switch between these themes (e.g., a toggle button).
  4. Testing and debugging to ensure visual consistency across the application.

This process can be error-prone and time-consuming, especially for large or complex UIs. Screenshot-to-code tools can help with the initial layout, but they don't understand the underlying logic or user interactions.

Replay: Behavior-Driven Dark Mode#

Replay offers a fundamentally different approach. By analyzing a video recording of a user interacting with a dark mode UI, Replay can:

  • Generate the necessary HTML, CSS, and JavaScript code.
  • Identify the theme switching mechanism.
  • Reconstruct the UI's behavior, including the dark mode toggle.
  • Integrate with backend services like Supabase for persistent theme preferences.

This approach significantly reduces development time and ensures that the generated UI accurately reflects the intended user experience.

How Replay Works: A Technical Overview#

Replay's video-to-code engine leverages several key technologies:

  1. Video Analysis: Replay analyzes the video frame-by-frame, identifying UI elements, their properties, and their interactions.
  2. Behavior Recognition: Using advanced AI models, Replay understands the user's intent and the underlying logic of the UI. This includes recognizing patterns like theme switching, form submissions, and data fetching.
  3. Code Generation: Replay generates clean, well-structured code that accurately reflects the UI's appearance and behavior. This code can be customized and integrated into existing projects.
  4. Supabase Integration: Replay can automatically integrate with Supabase to store and retrieve user preferences, such as their preferred theme.

Creating a Dark Mode UI with Replay: A Step-by-Step Guide#

Let's walk through the process of creating a dark mode UI using Replay.

Step 1: Record a Video#

Record a video of yourself interacting with a dark mode UI. Make sure to clearly demonstrate the theme switching functionality. This could be an existing website with dark mode, or a prototype you've created. The clearer the video, the better Replay can reconstruct the UI.

💡 Pro Tip: Speak clearly in the video, describing your actions. This helps Replay understand your intent. For example, say "Now I'm clicking the dark mode toggle" as you click it.

Step 2: Upload to Replay#

Upload the video to Replay. Replay will process the video and generate the code.

Step 3: Review and Customize the Code#

Replay will present you with the generated code, including HTML, CSS, and JavaScript. Review the code and make any necessary customizations. You can adjust the styling, add new features, or integrate with your existing codebase.

typescript
// Example: Dark mode toggle function generated by Replay const toggleDarkMode = () => { const body = document.body; body.classList.toggle('dark-mode'); // Save preference to local storage (optional) localStorage.setItem('darkMode', body.classList.contains('dark-mode')); }; // Check for stored preference on page load window.onload = () => { if (localStorage.getItem('darkMode') === 'true') { document.body.classList.add('dark-mode'); } };

This code snippet shows a simple JavaScript function generated by Replay to toggle dark mode. It also includes optional code to save the user's preference to local storage.

Step 4: Style Injection and Fine-Tuning#

Replay allows for style injection, enabling you to easily modify the generated CSS. This is particularly useful for fine-tuning the dark mode theme to match your brand's aesthetic.

Step 5: Integrate with Supabase (Optional)#

If you want to persist user preferences across sessions, you can integrate Replay with Supabase. Replay can automatically generate the necessary Supabase functions to store and retrieve theme preferences.

Comparison: Replay vs. Traditional and Screenshot-to-Code#

FeatureTraditionalScreenshot-to-CodeReplay
Video Input
Behavior AnalysisPartial
Dark Mode Toggle Recognition
Code QualityManualVariableHigh
Time to ImplementationHighMediumLow
Supabase IntegrationManualManualAutomated

This table highlights the key advantages of Replay over traditional methods and screenshot-to-code tools. Replay's ability to analyze video and understand behavior significantly reduces development time and improves code quality.

Benefits of Using Replay for Dark Mode UI Development#

  • Rapid Prototyping: Quickly generate working dark mode UIs from video recordings.
  • Reduced Development Time: Automate the process of creating and implementing dark mode themes.
  • Improved Code Quality: Replay generates clean, well-structured code that is easy to maintain.
  • Enhanced User Experience: Ensure visual consistency and a seamless user experience across all devices.
  • Behavior-Driven Development: Focus on the user's intent and the UI's behavior, rather than just its appearance.
  • Multi-page Generation: Replay can handle complex, multi-page UIs, making it suitable for large-scale applications.
  • Product Flow Maps: Replay can generate visual maps of the user's journey through the UI, helping you identify areas for improvement.

📝 Note: Replay is constantly evolving, with new features and improvements being added regularly.

⚠️ Warning: While Replay significantly reduces development time, it's still important to review and customize the generated code to ensure it meets your specific requirements.

css
/* Example: CSS generated by Replay for dark mode */ body.dark-mode { background-color: #121212; color: #ffffff; } .dark-mode .card { background-color: #212121; color: #eeeeee; } /* Add more dark mode styles as needed */

This CSS snippet shows an example of the dark mode styles generated by Replay. You can easily customize these styles to match your brand's aesthetic.

Frequently Asked Questions#

Is Replay free to use?#

Replay offers a free tier with limited usage. Paid plans are available for higher usage and access to advanced features. Check the Replay pricing page for details.

How is Replay different from v0.dev?#

While both tools aim to accelerate UI development, Replay distinguishes itself through its video-to-code engine and behavior-driven reconstruction. v0.dev primarily relies on text prompts and code generation, whereas Replay analyzes actual user interactions captured in video, resulting in more accurate and functional UI reconstructions. Replay understands what the user is trying to achieve, not just what they see on the screen.

What types of UIs can Replay generate?#

Replay can generate a wide range of UIs, from simple landing pages to complex web applications. It supports various UI frameworks and libraries, including React, Vue, and Angular.

How accurate is Replay's code generation?#

Replay's code generation is highly accurate, thanks to its advanced AI models and behavior-driven reconstruction. However, it's always recommended to review and customize the generated code to ensure it meets your specific requirements.

Can I use Replay to generate mobile UIs?#

Yes, Replay can be used to generate mobile UIs, as long as you have a video recording of the UI in action.


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