접근성 & WCAG
시맨틱 HTML
<!-- 의미 있는 요소를 제네릭 div 대신 사용 -->
<header>
<nav aria-label="주 내비게이션">
<ul>
<li><a href="/" aria-current="page">홈</a></li>
<li><a href="/products">제품</a></li>
<li><a href="/about">소개</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h1>제품 상세</h1>
<section aria-labelledby="specs-heading">
<h2 id="specs-heading">사양</h2>
<dl>
<dt>무게</dt>
<dd>1.2 kg</dd>
<dt>크기</dt>
<dd>30 x 20 x 10 cm</dd>
</dl>
</section>
</article>
</main>
<footer>
<p>© 2024 회사명</p>
</footer>
랜드마크에는 <div> 대신 <nav>, <main>, <article>, <section>, <aside>를 사용하세요. 스크린 리더는 이 요소들을 사용하여 페이지를 탐색합니다.
ARIA 패턴
function Modal({ isOpen, onClose, title, children }) {
if (!isOpen) return null;
return (
<div
role="dialog"
aria-modal="true"
aria-labelledby="modal-title"
onKeyDown={(e) => e.key === "Escape" && onClose()}
>
<h2 id="modal-title">{title}</h2>
<div>{children}</div>
<button onClick={onClose} aria-label="대화상자 닫기">
<XIcon aria-hidden="true" />
</button>
</div>
);
}
function Tabs({ tabs, activeIndex, onChange }) {
return (
<div>
<div role="tablist" aria-label="설정 섹션">
{tabs.map((tab, i) => (
<button
key={tab.id}
role="tab"
id={`tab-${tab.id}`}
aria-selected={i === activeIndex}
aria-controls={`panel-${tab.id}`}
tabIndex={i === activeIndex ? 0 : -1}
onClick={() => onChange(i)}
onKeyDown={(e) => handleArrowKeys(e, i, tabs.length, onChange)}
>
{tab.label}
</button>
))}
</div>
{tabs.map((tab, i) => (
<div
key={tab.id}
role="tabpanel"
id={`panel-${tab.id}`}
aria-labelledby={`tab-${tab.id}`}
hidden={i !== activeIndex}
tabIndex={0}
>
{tab.content}
</div>
))}
</div>
);
}
키보드 내비게이션
function handleArrowKeys(
event: React.KeyboardEvent,
currentIndex: number,
totalItems: number,
onSelect: (index: number) => void
) {
let newIndex = currentIndex;
switch (event.key) {
case "ArrowRight":
case "ArrowDown":
newIndex = (currentIndex + 1) % totalItems;
break;
case "ArrowLeft":
case "ArrowUp":
newIndex = (currentIndex - 1 + totalItems) % totalItems;
break;
case "Home":
newIndex = 0;
break;
case "End":
newIndex = totalItems - 1;
break;
default:
return;
}
event.preventDefault();
onSelect(newIndex);
}
모든 대화형 요소는 키보드로 접근 가능해야 합니다. Tab으로 초점 이동, Enter/Space으로 활성화, 화살표 키로 컴포넌트 내 탐색을 수행합니다.
폼 접근성
function SignupForm() {
return (
<form aria-labelledby="form-title" noValidate>
<h2 id="form-title">계정 만들기</h2>
<div>
<label htmlFor="email">이메일 주소</label>
<input
id="email"
type="email"
required
aria-required="true"
aria-describedby="email-hint email-error"
aria-invalid={hasError ? "true" : undefined}
/>
<p id="email-hint">이메일을 절대 공유하지 않습니다.</p>
{hasError && (
<p id="email-error" role="alert">
유효한 이메일 주소를 입력해 주세요.
</p>
)}
</div>
<button type="submit">계정 만들기</button>
</form>
);
}
색상과 대비
:root {
--text-primary: #1a1a1a; /* 흰색 배경에서 15.3:1 */
--text-secondary: #595959; /* 흰색 배경에서 7.0:1 */
--text-on-primary: #ffffff; /* 브랜드 색상에서 4.5:1 보장 */
--border-focus: #0066cc; /* 가시적 포커스 링 */
}
*:focus-visible {
outline: 3px solid var(--border-focus);
outline-offset: 2px;
}
.error-message {
color: #d32f2f;
/* 색상에만 의존하지 말고 아이콘이나 텍스트 접두사 추가 */
}
.error-message::before {
content: "오류: ";
font-weight: bold;
}
WCAG AA는 일반 텍스트에 4.5:1, 큰 텍스트(18px 볼드 또는 24px 일반)에 3:1의 대비를 요구합니다.
안티 패턴
- 클릭 가능한 요소에
button이나a대신div와span사용 - 대체 지표 없이 포커스 아웃라인 제거
- 정보 전달을 위해 색상에만 의존(빨간색=오류, 초록색=성공)
- 요소를 이미 라벨링하는 가시 텍스트가 있을 때
aria-label사용 - 일시 정지 메커니즘 없이 미디어 자동 재생
- 키보드 사용자를 위한 건너뛰기 내비게이션 링크 누락
체크리스트
- 모든 대화형 요소가 키보드로 접근 가능 (Tab, Enter, Escape, 화살표)
- 시맨틱 HTML 랜드마크 사용 (
nav,main,article,section) - 이미지에 설명적인
alt텍스트가 있음 (또는 장식용일 경우alt="") - 색상 대비가 WCAG AA를 충족 (일반 텍스트 4.5:1, 큰 텍스트 3:1)
- 모든 대화형 요소에서 포커스 표시기가 보임
- 폼 입력에 연결된
<label>요소가 있음 - 오류 메시지가
role="alert"를 통해 스크린 리더에 전달됨 - 페이지를 스크린 리더(VoiceOver, NVDA)와 키보드만으로 테스트했음