HTML <audio> 요소는 문서에 소리 콘텐츠를 포함할 때 사용합니다. src 특성 또는 <source> 요소를 사용해 한 개 이상의 오디오 소스를 지정할 수 있으며, 다수를 지정한 경우 가장 적절한 소스를 브라우저가 고릅니다. MediaStream을 사용하면 미디어 스트림을 바라볼 수도 있습니다.


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

지정한 경우, 전체 오디오 파일의 다운로드를 기다리지 않고 가능한 빠른 시점에 재생을 시작합니다.
참고: 오디오 및 오디오를 가진 비디오를 자동으로 재생하는 사이트는 사용자 경험에 악영향을 끼칠 수 있으므로 피해야 합니다. 반드시 자동 재생을 제공해야 한다면 사용자의 명시적인 동의를 얻어야 하도록 해야 합니다. 그러나, 미디어 소스가 사용자의 선택에 의해 나중에 정해지는 경우라면 자동 재생이 유용할 수 있습니다. 자동 재생 안내서를 방문하고 추가 정보와 적절한 사용법을 알아보세요.
지정한 경우 오디오 재생, 볼륨, 탐색, 일시 정지 컨트롤을 브라우저에서 제공합니다.
CORS를 사용해 지정한 오디오 파일을 가져올지 나타내는 열거형 특성. 교차 출처 활성화 리소스<canvas> 요소에 사용해도 캔버스를 "오염"시키지 않습니다. 가능한 값은 다음과 같습니다.
자격 증명 없이 교차 출처 요청을 전송합니다. 즉, Origin: HTTP 헤더를 쿠키, X.509 인증서, HTTP Basic 인증 없이 전송합니다. 서버에서 Access-Control-Allow-Origin: HTTP 헤더를 지정하지 않음으로써 요청 출처 사이트에 자격 증명을 보내지 않는다면 이미지는 "오염"되고, 사용처가 제한됩니다.
자격 증명과 함께 교차 출처 요청을 전송합니다. 즉, Origin: HTTP 헤더를 쿠키, X 509 인증서, 또는 HTTP Basic 이증과 함께 전송합니다. 서버에서 Access-Control-Allow-Origin: HTTP 헤더를 통한 자격 증명을 요청 출처 사이트에 보내지 않는다면 이미지는 "오염"되고, 사용처가 제한됩니다.
특성이 존재하지 않으면 리소스를 CORS 요청 없이(Origin: HTTP 헤더 없이) 가져오므로, <canvas>를 오염시키게 됩니다. 유효하지 않은 값의 경우 anonymous 키워드를 사용한 것으로 간주합니다.

Reading currentTime returns a double-precision floating-point value indicating the current playback position, in seconds, of the audio. If the audio's metadata isn't available yet—thereby preventing you from knowing the media's start time or duration—currentTime instead indicates, and can be used to change, the time at which playback will begin. Otherwise, setting currentTime sets the current playback position to the given time and seeks the media to that position if the media is currently loaded.

If the audio is being streamed, it's possible that the user agent may not be able to obtain some parts of the resource if that data has expired from the media buffer. Other audio may have a media timeline that doesn't start at 0 seconds, so setting currentTime to a time before that would fail. For example, if the audio's media timeline starts at 12 hours, setting currentTime to 3600 would be an attempt to set the current playback position well before the beginning of the media, and would fail. The getStartDate() method can be used to determine the beginning point of the media timeline's reference frame.

disableRemotePlayback This is an experimental API that should not be used in production code.
A Boolean attribute used to disable the capability of remote playback in devices that are attached using wired (HDMI, DVI, etc.) and wireless technologies (Miracast, Chromecast, DLNA, AirPlay, etc). See this proposed specification for more information.

In Safari, you can use x-webkit-airplay="deny" as a fallback.

duration Read only
A double-precision floating-point value which indicates the duration (total length) of the audio in seconds, on the media's timeline. If no media is present on the element, or the media is not valid, the returned value is NaN. If the media has no known end (such as for live streams of unknown duration, web radio, media incoming from WebRTC, and so forth), this value is +Infinity.
A Boolean attribute: if specified, the audio player will automatically seek back to the start upon reaching the end of the audio.
A Boolean attribute that indicates whether the audio will be initially silenced. Its default value is false.
This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:
  • none: Indicates that the audio should not be preloaded.
  • metadata: Indicates that only audio metadata (e.g. length) is fetched.
  • auto: Indicates that the whole audio file can be downloaded, even if the user is not expected to use it.
  • empty string: A synonym of the auto value.

The default value is different for each browser. The spec advises it to be set to metadata.

Usage notes:
  • The autoplay attribute has precedence over preload. If autoplay is specified, the browser would obviously need to start downloading the audio for playback.
  • The browser is not forced by the specification to follow the value of this attribute; it is a mere hint.
The URL of the audio to embed. This is subject to HTTP access controls. This is optional; you may instead use the <source> element within the audio block to specify the audio to embed.

Time offsets are specified as float values indicating the number of seconds to offset.

Note: The time offset value definition has not yet been completed in the HTML5 specification and is subject to change.


이벤트 이름 발생 조건
audioprocess The input buffer of a ScriptProcessorNode is ready to be processed.
canplay The browser can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content.
canplaythrough The browser estimates it can play the media up to its end without stopping for content buffering.
complete The rendering of an OfflineAudioContext is terminated.
durationchange The duration attribute has been updated.
emptied The media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the load() method is called to reload it.
ended Playback has stopped because the end of the media was reached.
loadeddata The first frame of the media has finished loading.
loadedmetadata The metadata has been loaded.
pause Playback has been paused.
play Playback has begun.
playing Playback is ready to start after having been paused or delayed due to lack of data.
ratechange The playback rate has changed.
seeked A seek operation completed.
seeking A seek operation began.
stalled The user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
suspend Media data loading has been suspended.
timeupdate The time indicated by the currentTime attribute has been updated.
volumechange The volume has changed.
waiting Playback has stopped because of a temporary lack of data

사용 일람

Browsers don't all support the same file types and audio codecs; you can provide multiple sources inside nested <source> elements, and the browser will then use the first one it understands:

<audio controls>
  <source src="myAudio.mp3" type="audio/mpeg">
  <source src="myAudio.ogg" type="audio/ogg">
  <p>Your browser doesn't support HTML5 audio. Here is
     a <a href="myAudio.mp4">link to the audio</a> instead.</p>

We offer a substantive and thorough guide to media file types and the audio codecs that can be used within them. Also available is a guide to the codecs supported for video.

Other usage notes:

  • If you don't specify the controls attribute, the audio player won't include the browser's default controls. You can, however, create your own custom controls using JavaScript and the HTMLMediaElement API.
  • To allow precise control over your audio content, HTMLMediaElements fire many different events. This also provides a way to monitor the audio's fetching process so you can watch for errors or detect when enough is available to begin to play or manipulate it.
  • You can also use the Web Audio API to directly generate and manipulate audio streams from JavaScript code rather than streaming pre-existing audio files.
  • <audio> elements can't have subtitles or captions associated with them in the same way that <video> elements can. See WebVTT and Audio by Ian Devlin for some useful information and workarounds.

A good general source of information on using HTML <audio> is the Video and audio content beginner's tutorial.

Styling with CSS

The <audio> element has no intrinsic visual output of its own unless the controls attribute is specified, in which case the browser's default controls are shown.

The default controls have a display value of inline by default, and it is often a good idea set the value to block to improve control over positioning and layout, unless you want it to sit within a text block or similar.

You can style the default controls with properties that affect the block as a single unit, so for example you can give it a border and border-radius, padding, margin, etc. You can't however style the individual components inside the audio player (e.g. change the button size or icons, change the font, etc.), and the controls are different across the different browsers.

To get a consistent look and feel across browsers, you'll need to create custom controls; these can be marked up and styled in whatever way you want, and then JavaScript can be used along with the HTMLMediaElement API to wire up their functionality.

Video player styling basics provides some useful styling techniques — it is written in the context of <video>, but much of it is equally applicable to <audio>.

Detecting addition and removal of tracks

You can detect when tracks are added to and removed from an <audio> element using the addtrack and removetrack events. However, these events aren't sent directly to the <audio> element itself. Instead, they're sent to the track list object within the <audio> element's HTMLMediaElement that corresponds to the type of track that was added to the element:

An AudioTrackList containing all of the media element's audio tracks. You can add a listener for addtrack to this object to be alerted when new audio tracks are added to the element.
Add an addtrack listener to this VideoTrackList object to be informed when video tracks are added to the element.
Add an addtrack event listener to this TextTrackList to be notified when new text tracks are added to the element.

Note: Even though it's an <audio> element, it still has video and text track lists, and can in fact be used to present video, although the use interface implications can be odd.

For example, to detect when audio tracks are added to or removed from an <audio> element, you can use code like this:

var elem = document.querySelector("audio");

elem.audioTrackList.onaddtrack = function(event) {

elem.audioTrackList.onremovetrack = function(event) {

This code watches for audio tracks to be added to and removed from the element, and calls a hypothetical function on a track editor to register and remove the track from the editor's list of available tracks.

You can also use addEventListener() to listen for the addtrack and removetrack events.


Basic usage

The following example shows simple usage of the <audio> element to play an OGG file. It will autoplay due to the autoplay attribute—if the page has permission to do so—and also includes fallback content.

<!-- Simple audio playback -->
  Your browser does not support the <code>audio</code> element.

For details on when autoplay works, how to get permission to use autoplay, and how and when it's appropriate to use autoplay, see our autoplay guide.

<audio> element with <source> element

This example specifies which audio track to embed using the src attribute on a nested <source> element rather than directly on the <audio> element. It is always useful to include the file's MIME type inside the type attribute, as the browser is able to instantly tell if it can play that file, and not waste time on it if not.

<audio controls>
  <source src="foo.wav" type="audio/wav">
  Your browser does not support the <code>audio</code> element.

<audio> with multiple <source> elements

This example includes multiple <source> elements. The browser tries to load the first source element (Opus) if it is able to play it; if not it falls back to the second (Vorbis) and finally back to MP3:

<audio controls>
 <source src="foo.opus" type="audio/ogg; codecs=opus"/>
 <source src="foo.ogg" type="audio/ogg; codecs=vorbis"/>
 <source src="foo.mp3" type="audio/mpeg"/>

접근성 고려사항

Audio with spoken dialog should provide both captions and transcripts that accurately describe its content. Captions, which are specified using WebVTT, allow people who are experiencing hearing loss to understand an audio recording's content as the recording is being played, while transcripts allow people who need additional time to be able to review the recording's content at a pace and format that is comfortable for them.

If automatic captioning services are used, it is important to review the generated content to ensure it accurately represents the source audio.

The <audio> element doesn't directly support WebVTT. You will have to find a library or framework that provides the capability for you, or write the code to display captions yourself. One option is to play your audio using a <video> element, which does support WebVTT.

In addition to spoken dialog, subtitles and transcripts should also identify music and sound effects that communicate important information. This includes emotion and tone. For example, in the WebVTT below, note the use of square brackets to provide tone and emotional insight to the viewer; this can help establish the mood otherwise provided using music, nonverbal sounds and crucial sound effects, and so forth.

00:00:00 --> 00:00:45
[Energetic techno music]

00:00:46 --> 00:00:51
Welcome to the Time Keeper's podcast! In this episode we're discussing which Swisswatch is a wrist switchwatch?

00:00:52 --> 00:01:02
[Laughing] Sorry! I mean, which wristwatch is a Swiss wristwatch?

Also it's a good practice to provide some content (such as the direct download link) as a fallback for viewers who use a browser in which the <audio> element is not supported:

<audio controls>
  <source src="myAudio.mp3" type="audio/mpeg">
  <source src="myAudio.ogg" type="audio/ogg">
    Your browser doesn't support HTML5 audio.
    Here is a <a href="myAudio.mp4">link to download the audio</a> instead.

기술 요약

콘텐츠 카테고리 플로우 콘텐츠, 구문 콘텐츠, 내장 콘텐츠. controls 특성을 가진 경우, 대화형 콘텐츠 및 뚜렷한 콘텐츠.
가능한 콘텐츠

src 특성을 가진 경우 0개 이상의 <track> 요소와 그 이후의 투명한 콘텐츠. 단, 다른 <audio><video> 요소는 불가능.

그 외의 경우 0개 이상의 <source> 요소와 0개 이상의 <track> 요소, 그리고 이후의 투명한 콘텐츠. 단, 다른 <audio><video> 요소는 불가능.

태그 생략 None, both the starting and ending tag are mandatory.
가능한 부모 요소 내장 콘텐츠를 허용하는 모든 요소.
암시적 ARIA 역할 대응하는 역할 없음
가능한 ARIA 역할 application
DOM 인터페이스 HTMLAudioElement


브라우저 호환성

BCD tables only load in the browser

같이 보기