앞선 내용에서 웹 접근성이 무엇인지를 살펴봤고, 그 중에서 스크린 리더가 글을 읽어주는 규칙에 대해서 알아봤다.
이번에는 그 스크린 리더가 내용을 읽어주는 이름과 설명을 어떻게 배치하고 지어야하는지를 학습해보고자 한다.
🗣️ 접근 가능한 설명
접근 가능한 이름
작성하기 위한 규칙
<form>
은 <label>
로, <table>
은 <caption>
으로, <img>
는 <figure>
로 이용하여 해당 태그의 이름을 지정하는 기법을 사용하는 것이 접근성을 향상시키는 데 도움이 된다.role
attribute를 부여하지 말자.
role
attribute를 사용하고 있다면, 해당 내용이 읽히므로 aria-label
등을 통해 읽힐 필요가 없다.
role
attribute를 둘 다 쓴다면 하나만 쓰도록 한다.
<button role=”button”>
은 ‘버튼 버튼’으로 읽히게 된다.<section>
이라고 해도 주요 기사를 담는 <section>
과 논평을 담은 <section>
은 같을 수가 없으므로, 각각의 고유한 이름을 담도록 해주자.이름을 지정하는 방법
후손 요소들에 존재하는 문자열 내용을 이름으로 지정하는 방법
이건 이해가 잘 안 되어서 코드를 보면서 설명하는 게 빠르다.
<ul role="tree">
<li role="treeitem">과일
<ul role="group">
<li role="treeitem">사과</li>
<li role="treeitem">바나나</li>
<li role="treeitem">오렌지</li>
</ul>
</li>
</ul>
위의 코드를 보면 tree라는 역할(role)이 부여된 요소에 접근 가능한 이름을 부여하려면, 후손에 treeitem이라는 role을 가진 요소를 통해 접근 가능한 이름을 부여할 수 있다.
여기서 ‘후손’이라는 건 직계 자식이 아닌 요소의 문자열도 받아올 수 있다는 건데, 만약 ‘과일’이라는 글자가 없다면 tree의 접근 가능한 이름은 그 다음에 나열되는 treeitem인 ‘사과’가 될 수 있다.
aria-label을 이용해 직접적으로 이름을 지정하는 방법
aria-labelledby를 이용해 간접적으로 이름을 지정하는 방법
<label>
에 for
attribute를 사용하는 것과 비슷하다.
<label for="night-mode">야간 모드</label>
<input type="checkbox" role="switch" id="night-mode">
위와 같이 <label>
을 <input>
에 묶고 싶을 때, <label>
의 for
attribute에 <input>
의 id
를 붙이는 것이 일반적이다.
aria-labelledby
도 이 방식처럼 이용하면 된다.
<span id="night-mode-label" hidden>야간 모드</span>
<input type="checkbox" role="switch" aria-labelledby="night-mode-label">
위의 코드와 같이 <span>
요소를 숨겨주고 aria-labelledby
를 통해 <span>
을 묶어줌으로서 <input>
의 접근 가능한 이름을 ‘야간 모드’로 지정할 수 있다.
aria-labelledby는 다음과 같은 특징이 있다.
**<label>
, <caption>
, <legend>
, <figcaption>
등을 활용해 이름을 지정하는 방법**
<label>
는 다른 요소와 엮어주는 것으로 이름을 지정해준다.
<label>
<input type="checkbox" name="subscribe">
</label>
id
와 for
를 활용해 이름을 지정하는 방법
<input type="checkbox" name="subscribe" id="subscribe_checkbox">
<label for="subscribe_checkbox">뉴스레터 구독</label>
<legend>
는 form
내에서 그룹화할 양식들의 이름을 지정해준다.
<fieldset>
<legend>시작 클래스 선택</legend>
<label><input type="radio" name="starter-class" value="green">Green</label>
<label><input type="radio" name="starter-class" value="red">Red</label>
<label><input type="radio" name="starter-class" value="blue">Blue</label>
</fieldset>
<caption>
과 <figcaption>
은 표나 이미지에 붙일 이름을 지정해준다.
aria-label
이나 aria-labelledby
를 사용하지 않아야 접근 가능한 이름으로 지정된다.aria-labelledby
를 통해 참조되어야 접근 가능한 이름으로 지정된다.접근 가능한 설명
설명을 지정하는 방법
aria-describedby
를 이용하는 방법
aria-labelledby
를 사용하는 방식과 유사하다.aria-describedby
attribute에 id
를 지정(마크업)하면 해당 내용을 접근 가능한 설명으로 배치할 수 있다.<button aria-describedby="trash-desc">휴지통으로 이동</button>
...
<p id="trash-desc">휴지통의 항목은 30일 후 영구적으로 제거될 것입니다.</p>
<!-- 접근 가능한 설명은 '문자열'이므로 이미지를 가져와 대체 텍스트를 작성하는 아래의 방법도 가능하다. -->
<!-- 위와 아래는 같은 내용으로 읽힌다. -->
<button aria-describedby="trash-desc"><img src="bin.svg" alt="휴지통">으로 이동</button>
...
<p id="trash-desc"><img src="bin.svg" alt="휴지통">의 항목은 30일 후 영구적으로 제거될 것입니다.</p>
aria-describedby
는 aria-labelledby
처럼 내용이 숨겨져 있어도 참조가 가능하다.<label for="username">Username</label>
<input id="username" name="username" aria-describedby="username-desc">
<button aria-expanded="false" aria-controls="username-desc" aria-label="Help about username">?</button>
<p id="username-desc" hidden>
username은 이 서비스에 로그인하는데 사용되는 이름입니다.
</p>
<table>
에서 <caption>
을 사용하는 방법
<table>
에서는 <caption>
을 이용해 접근 가능한 이름을 지정할 수 있다.<table>
이 aria-labelledby
나 aria-label
을 통해 어떤 id를 마크업하고 있으면, 마크업한 id의 문자열을 접근 가능한 이름으로 받는다.
<caption>
은 접근 가능한 설명으로 받는다.<h2 id="events-heading">다가오는 일정</h2>
<table aria-labelledby="events-heading">
<caption>
다가오는 일정의 달력, 27주에서 31주까지, 매주 월요일에 시작합니다.
첫 번째 열은 주차입니다.
</caption>
<tr><th>주차<th>월<th>화<th>수<th>목<th>금<th>토<th>일
<tr><td>27<td><td><td><td><td><td><td>
<tr><td>28<td><td><td><td><td><td><td><a href="/events/9856">왕세자비 생일</a>
<tr><td>29<td><td><td><td><td><td><td>
<tr><td>30<td><td><td><td><td><td><td>
<tr><td>31<td><td><td><td><td><td><td>
</table>
<caption>
과 비슷한 역할을 하는 <figure>
의 <figcaption>
의 경우, <caption>
과 다르게 aria-describedby
attribute를 통해 <figcaption>
을 연결해줘야 접근 가능한 설명으로 동작된다.