--- title: ': 대화 상자 요소' slug: Web/HTML/Element/dialog tags: - Element - HTML - HTML interactive elements - Reference - Web - polyfill - 대화 상자 translation_of: Web/HTML/Element/dialog ---
{{HTMLRef}}

HTML <dialog> 요소는 닫을 수 있는 경고, 검사기, 창 등 대화 상자 및 기타 다른 상호작용 가능한 컴포넌트를 나타냅니다.

콘텐츠 카테고리 플로우 콘텐츠, 구획 루트.
가능한 콘텐츠 플로우 콘텐츠.
태그 생략 {{no_tag_omission}}
가능한 부모 요소 플로우 콘텐츠를 허용하는 모든 요소.
암시적 ARIA 역할 dialog
가능한 ARIA 역할 {{ARIARole("alertdialog")}}
DOM 인터페이스 {{domxref("HTMLDialogElement")}}

특성

이 요소는 전역 특성을 포함합니다.

tabindex 특성을 <dialog> 요소에 사용해서는 안됩니다.

{{htmlattrdef("open")}}
대화 상자가 활성 상태이며 상호작용할 수 있음을 나타냅니다. open 특성이 없을 때 대화 상자가 사용자에게 보여서는 안됩니다.

사용 일람

예제

간단한 예제

<dialog open>
  <p>여러분 안녕하세요!</p>
</dialog>

고급 예제

다음 예제는 "상세정보 업데이트" 버튼을 클릭할 경우 양식을 포함한 팝업 대화 상자를 엽니다.

HTML

<!-- 간단한 양식을 포함한 팝업 대화 상자 -->
<dialog id="favDialog">
  <form method="dialog">
    <p><label>좋아하는 동물:
      <select>
        <option></option>
        <option>아르테미아</option>
        <option>레서판다</option>
        <option>거미원숭이</option>
      </select>
    </label></p>
    <menu>
      <button value="cancel">취소</button>
      <button id="confirmBtn" value="default">확인</button>
    </menu>
  </form>
</dialog>

<menu>
  <button id="updateDetails">상세정보 업데이트</button>
</menu>

<output aria-live="polite"></output>

JavaScript

var updateButton = document.getElementById('updateDetails');
var favDialog = document.getElementById('favDialog');
var outputBox = document.getElementsByTagName('output')[0];
var selectEl = document.getElementsByTagName('select')[0];
var confirmBtn = document.getElementById('confirmBtn');

// “Update details” button opens the <dialog> modally
updateButton.addEventListener('click', function onOpen() {
  if (typeof favDialog.showModal === "function") {
    favDialog.showModal();
  } else {
    alert("The <dialog> API is not supported by this browser");
  }
});
// "Favorite animal" input sets the value of the submit button
selectEl.addEventListener('change', function onSelect(e) {
  confirmBtn.value = selectEl.value;
});
// "Confirm" button of form triggers "close" on dialog because of [method="dialog"]
favDialog.addEventListener('close', function onClose() {
  outputBox.value = favDialog.returnValue + " button clicked - " + (new Date()).toString();
});

결과

{{EmbedLiveSample("고급_예제", "100%", 300)}}

명세

Specification Status Comment
{{SpecName('HTML WHATWG', 'forms.html#the-dialog-element', '<dialog>')}} {{Spec2('HTML WHATWG')}}
{{SpecName('HTML5.1', 'interactive-elements.html#the-dialog-element', '<dialog>')}} {{Spec2('HTML5.1')}} 최초 정의

브라우저 호환성

{{Compat("html.elements.dialog")}}

폴리필

지원하지 않는 브라우저에서 <dialog>를 사용하려면 dialog-polyfill을 추가하세요.

같이 보기