HTML Academy · 강의

토글을 위한 aria-expanded 및 aria-controls

ARIA로 접근 가능한 공개 위젯과 아코디언 만들기

레슨 1/413개 단계

토글을 위한 aria-expanded 및 aria-controls은(는) CoddyKit의 무료 HTML Academy 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 HTML Academy 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. HTML Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

토글 패턴 개요

토글 컨트롤(아코디언, 드롭다운, 메뉴)은 열림/닫힘 상태를 전달하기 위해 ARIA가 필요합니다:

  • aria-expanded — 컨트롤의 열림/닫힘 상태를 나타냅니다
  • aria-controls — 컨트롤과 컨트롤이 제어하는 요소를 연결합니다

aria-expanded

aria-expanded는 제어되는 요소가 펼쳐져 있는지 접혀 있는지를 전달합니다:

<button aria-expanded="false" aria-controls="menu">
  Menu
</button>
<ul id="menu" hidden>
  <li><a href="/">Home</a></li>
</ul>
<script>
btn.addEventListener('click', () => {
  const expanded = btn.getAttribute('aria-expanded') === 'true';
  btn.setAttribute('aria-expanded', !expanded);
  menu.hidden = expanded;
});
</script>

aria-controls

aria-controls는 제어되는 요소의 id를 참조합니다:

<button
  id="details-btn"
  aria-expanded="false"
  aria-controls="details-panel"
>
  Show Details
</button>
<div id="details-panel" hidden>
  <p>Additional details go here...</p>
</div>
<!-- Screen reader: 'Show Details, button, collapsed'
     After click: 'Show Details, button, expanded' -->

아코디언 패턴

aria-expanded를 사용한 접근 가능한 아코디언:

<div class="accordion">
  <h3>
    <button
      aria-expanded="false"
      aria-controls="panel-1"
    >Section 1</button>
  </h3>
  <div id="panel-1" hidden>
    <p>Panel 1 content...</p>
  </div>

  <h3>
    <button
      aria-expanded="false"
      aria-controls="panel-2"
    >Section 2</button>
  </h3>
  <div id="panel-2" hidden>
    <p>Panel 2 content...</p>
  </div>
</div>

드롭다운 메뉴 패턴

접근 가능한 탐색 드롭다운:

<nav>
  <button
    aria-expanded="false"
    aria-haspopup="true"
    aria-controls="products-menu"
  >Products</button>

  <ul id="products-menu" role="menu" hidden>
    <li role="menuitem"><a href="/widget">Widget</a></li>
    <li role="menuitem"><a href="/gadget">Gadget</a></li>
  </ul>
</nav>

aria-haspopup

aria-haspopup는 컨트롤을 활성화하면 팝업이 열림을 암시합니다:

<button aria-haspopup="menu">File</button>
<!-- Values: true (menu), menu, listbox, tree, grid, dialog -->
<!-- Screen reader: 'File, button, has popup' -->

<!-- Note: aria-haspopup="true" is equivalent to "menu" -->
<!-- Use specific values when the popup type matters -->

details/summary ARIA 보완

기본 details/summary는 이미 펼침 상태를 전달하므로 ARIA가 필요하지 않습니다:

<details>
  <summary>FAQ Question</summary>
  <p>Answer goes here.</p>
</details>
<!-- Browser automatically provides aria-expanded
     and the disclosure widget semantics -->
<!-- No need to add aria-expanded manually to summary -->

aria-expanded 상태를 위한 CSS

aria-expanded를 CSS 훅으로 사용하십시오:

/* Panel hidden by default: */
[aria-controls] + [hidden] {
  display: none;
}

/* Or using aria-expanded on the button: */
[aria-expanded="false"] + .panel {
  display: none;
}

[aria-expanded="true"] + .panel {
  display: block;
}

/* Rotate arrow icon: */
[aria-expanded="true"] .arrow {
  transform: rotate(180deg);
}

토글의 키보드 요구 사항

토글 구성 요소는 키보드 상호작용을 지원해야 합니다:

  • Enter 또는 Space — 토글 버튼 활성화
  • Escape — 드롭다운 또는 메뉴 닫기
  • 화살표 키 — 열린 메뉴 안에서 이동

토글 후 focus 관리

콘텐츠를 토글한 후에는 focus를 적절하게 관리하십시오:

// Accordion: focus stays on the button (usually OK)
// Dropdown menu: move focus to first menu item on open

button.addEventListener('click', () => {
  const expanded = button.getAttribute('aria-expanded') === 'true';
  button.setAttribute('aria-expanded', !expanded);
  panel.hidden = expanded;

  if (!expanded) {
    // Opening a dropdown: focus first item
    panel.querySelector('a, button, [tabindex]')?.focus();
  }
});

모바일 고려 사항

모바일의 토글 구성 요소:

  • 터치 대상은 최소 44×44px이어야 합니다(WCAG 2.5.5)
  • aria-expanded는 모바일 화면 낭독기(iOS VoiceOver, Android TalkBack)에서 지원됩니다
  • 스와이프 제스처가 키보드 또는 버튼 활성화를 대신해서는 안 됩니다

빠른 확인

제어되는 섹션이 숨겨져 있을 때 aria-expanded에는 어떤 값을 지정해야 할까요?

복습: aria-expanded와 aria-controls

토글 ARIA의 핵심:

  • aria-expanded="true/false" — 컨트롤의 열림/닫힘 상태
  • aria-controls="id" — 컨트롤과 해당 패널을 연결합니다
  • aria-haspopup — 팝업을 사용할 수 있음을 암시합니다
  • 토글할 때마다 aria-expanded를 업데이트하십시오
  • 열린 메뉴 안으로 focus를 이동하고, 닫을 때 트리거로 focus를 돌려보내십시오
무료로 시작

AI 튜터와 함께 HTML을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
40
레슨
159

자주 묻는 질문

“토글을 위한 aria-expanded 및 aria-controls” 강의는 무료인가요?

네 — “토글을 위한 aria-expanded 및 aria-controls” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 HTML Academy 강의 전체를 잠금 해제할 수 있습니다. HTML Academy 강의에는 총 4개의 강의가 포함되어 있습니다.

“토글을 위한 aria-expanded 및 aria-controls”에서 뭘 배우나요?

ARIA로 접근 가능한 공개 위젯과 아코디언 만들기 브라우저에서 직접 실행하는 실습 코드로 HTML Academy을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

HTML Academy을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 HTML Academy은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.

“토글을 위한 aria-expanded 및 aria-controls” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 HTML Academy 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 HTML Academy 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 토글을 위한 aria-expanded 및 aria-controls
  2. aria-selected 및 탭 패턴
  3. 라이브 영역 aria-live aria-atomic aria-relevant
  4. 스크린 리더로 테스트하기
← HTML Academy(으)로 돌아가기