BlackMagic.js Examples

Explore real-world examples of BlackMagic.js in action. Each example demonstrates different features and use cases.

Sample Header
Content Area
This is how your content looks
Basic Implementation
The simplest possible dark mode implementation. Just three lines of code to add automatic dark mode to any website.
Beginner 3 lines CDN
Custom Theme
Dark Content
Custom background colors
Advanced Configuration
Custom background colors, adjustment factors, and persistence settings. Perfect for branded dark modes.
Advanced Custom Colors Persistence
CSS Classes
Performance Mode
Uses CSS classes for speed
CSS Class Mode
High-performance mode using CSS classes instead of inline styles. Perfect for large websites with many elements.
Performance CSS Classes Scalable
React App
Component
Framework integration
React Integration
How to integrate BlackMagic.js with React applications. Includes hooks and context patterns.
React Hooks Framework
♿ A11y Demo
WCAG 2.1
Perfect contrast ratios
Accessibility Features
Demonstrates WCAG 2.1 compliance, contrast ratio calculations, and accessibility best practices.
Accessibility WCAG 2.1 Contrast
🛒 Store
Product Card
$99.99
E-commerce Website
A complete e-commerce website example showing how BlackMagic handles complex layouts and brand colors.
E-commerce Complex Layout Brand Colors

Live Interactive Demo

Sample Website

Welcome to Our Website

This is a sample website that demonstrates how BlackMagic.js automatically adjusts colors for perfect dark mode. Notice how all elements mastertain proper contrast and readability.

Feature Card

Cards and containers automatically get proper backgrounds and borders that work in both light and dark modes.

Sidebar Content

Even complex layouts with nested backgrounds work perfectly. BlackMagic analyzes the entire DOM structure to ensure optimal color adjustments.

  • Automatic contrast adjustment
  • Brand color preservation
  • WCAG 2.1 compliance
  • Zero configuration required

Code Examples

Basic Implementation
<!-- Include BlackMagic -->
<script src="https://cdn.jsdelivr.net/npm/blackmagic-js@latest"></script>

<script>
// Initialize BlackMagic
const blackMagic = new BlackMagic();

// Add to any button
document.getElementById('darkToggle')
  .addEventListener('click', () => {
    blackMagic.toggle();
  });
</script>
Advanced Configuration
// Custom configuration
const blackMagic = new BlackMagic({
  backgroundColor: '#1a1a2e',  // Custom dark background
  factor: 0.6,                 // More aggressive adjustment
  themeClass: 'dark-theme',    // Use CSS classes
  cookieDuration: 365,         // Persist for 1 year
  autoSwitch: true             // Apply saved theme on load
});

// Check current theme
console.log(blackMagic.getCurrentTheme());

// Apply specific theme
blackMagic.applyTheme('dark');