다크모드는 어두운 환경에서 눈의 피로를 줄이고, OLED 화면에서 배터리를 절약할 수 있습니다.
또한 장시간 컴퓨터를 사용하는 사용자들에게 편안한 경험을 제공합니다.
구현 시 고려사항
• 대비율 유지 (최소 4.5:1)
• 순수 검정색 사용 자제 (#1f2937 권장)
• 이미지와 아이콘의 가시성 확인
• 테마 전환 시 깜빡임 방지
영구 저장 방법
💾
localStorage
클라이언트 측 저장 빠르고 간단
🍪
Cookie
서버 렌더링 시 초기 테마 적용
👤
사용자 계정
로그인 시 크로스 디바이스
🖥️
시스템 감지
prefers-color-scheme 자동 동기화
엣지 케이스 처리
시스템 설정 변경 감지
앱 실행 중 OS 다크모드가 변경되면 matchMedia로 감지하여 업데이트
임베디드 콘텐츠
iframe이나 서드파티 위젯은 테마 변경을 지원하지 않을 수 있음 - 경계 스타일 조정
플래시 방지
페이지 로드 시 잘못된 테마가 잠깐 보이는 것을 방지 - 인라인 스크립트로 사전 적용
애니메이션 감소 모드
prefers-reduced-motion이 활성화되면 트랜지션 비활성화
84. 다크모드 전환 상태
Design dark mode toggle transition:
**Toggle UI**:
- Switch component
- Or icon button (sun/moon)
- Position: settings or header
**State Sources**:
- User preference (stored)
- System preference (OS)
- Time-based (auto-switch)
**Preference Priority**:
1. Explicit user choice
2. System preference (if no choice)
3. Default: light mode
**Theme States**:
- Light theme active
- Dark theme active
- System preference (follows OS)
**Toggle Flow**:
1. User clicks toggle
2. Update state/store
3. Apply CSS class to root
4. Transition animations
5. Persist preference
**CSS Implementation**:
- `html.dark` class on root
- Or CSS variables switching
- Or data-theme attribute
**Transition Animation**:
- Color transition: 200-300ms
- All elements transition smoothly
- No flash of wrong theme
**Component Changes**:
- Background colors invert
- Text colors adjust
- Shadows adapt (lighter in dark)
- Images/icons may swap
**Icon Animation**:
- Sun morphs to moon
- Or rotation with fade
- Smooth, delightful
**Persistence**:
- localStorage preference
- Or user account setting
- Read on initial load
**Server Rendering**:
- Avoid flash: inline script
- Cookie for server hint
- Match client preference
**Edge Cases**:
- System changes while app open
- Embedded content (iframes)
- Third-party widgets
**Accessibility**:
- Respect prefers-reduced-motion
- Maintain contrast ratios
- Focus indicators visible
Tech: State diagram → next-themes / Tailwind dark mode