HTML <audio> tagS2C Home   « HTML <audio> tag

Definition

The <audio> tag is used to is used to embed audio content into a HTML document.

The <audio> tag can be used in conbination with the <source> element to provide a list of audios where the first valid one is played, or standalone.

The <audio> tag was introduced in HTML5.

Examples



<audio controls autoplay>
  <source src="../pages/bensound-summer.mp3" type="audio/ogg">
  <source src="../pages/bensound-summer.mp3" type="audio/mpeg">
</audio>

Royalty Free Music from Bensound

Required Attributes

NONE

Optional Attributes

autoplay - specifies the audio will play as soon as it is ready.


<!-- Valid values are an empty string or autofocus -->
<audio autoplay>Audio content here</audio>
<audio autoplay="autoplay">Audio content here</audio>

controls - specifies whether to display audio controls such as stop/play/pause.


<!-- Valid values are an empty string or autofocus -->
<audio controls>Audio content here</audio>
<audio controls="controls">Audio content here</audio>

loop - specifies whether to continue playing the audio in an endless loop.


<!-- Valid values are an empty string or loop -->
<audio loop>Audio content here</audio>
<audio loop="loop">Audio content here</audio>

muted - specifies whether the audio is muted.


<!-- Valid values are an empty string or muted -->
<audio muted>Audio content here</audio>
<audio muted="muted">Audio content here</audio>

preload specifies if the audio should be prelodaed and if so, how.


<!-- Valid values are auto, none and metadata,  -->
<audio preload="auto">Audio content here</audio>

src specifies the URL location of a audio file.


<!-- Required when source used in audio -->
<audio src="https://server2client.com/pages/ball.avi">Audio content here</audio>

Global Attributes

Common

class - specifies a classname for the element allowing you to apply the style of the predefined class to the content.


<audio class="classname">Audio content here</audio>

id - specifies a unique id for the element allowing you to apply the style of the predefined id to the content.


<audio id="idname">Audio content here</audio>

style - specifies an inline style for the element allowing you to apply the style to the content.


<audio style="color:red;text-align:left">Audio content here</audio>

title - specifies extra information about the content.


<audio title="information about the content">Audio content here</audio>

Keyboard

accesskey - specifies a keyboard shortcut to associate with the element.


<audio accesskey="aKeyValue">Audio content here</audio>

tabindex - specifies a tab order for the element.


<audio tabindex="someNumber">Audio content here</audio>

Language

dir - specifies the directional flow of the content.


   <!-- The text will flow from left to right -->
<audio dir="ltr">Audio content here</audio>

   <!-- The text will flow from right to left -->
<audio dir="rtl">Audio content here</audio>

lang - specifies a language code for the content of the element.


<audio lang="en">Audio content here</audio>

xml:lang - specifies a language code for the content of the element in XHTML documents.


<audio xml:lang="fr">Audio content here</audio>

spellcheck - specifies whether the element is to have its spelling checked.


<!-- Valid values are true and  false - default is inherited / browser specific. -->
<audio spellcheck="true">Audio content here</audio>

translate - specifies whether the content of the element can be translated.


<!-- Valid values are yes and  no - default is yes. -->
<audio translate="no">Audio content here</audio> 

Miscellaneous

contenteditable - specifies whether the content of the element is editable.


<!-- Valid values are true and  false - default is inherited. -->
<audio contenteditable="false">Audio content here</audio> 

draggable - specifies whether the the element is draggable.

Only text selections, images, and links can be dragged.


<!-- Valid values are true and  false - default is browser specific. -->
<audio draggable="true">Audio content here</audio>

hidden - specifies whether the element is not yet, or no longer, relevant.


<!-- Valid values are an empty string or hidden -->
<audio hidden>Audio content here</audio> 
<audio hidden="hidden">Audio content here</audio> 

Event Attributes

Document

onabort - The JavaScript code to be run on abort.


<audio onabort="go()">Audio content here</audio>   <!-- Executes the go() function -->

onerror - The JavaScript code to be run when an error occurs when the file is being loaded.


<audio onerror="go()">Audio content here</audio>   <!-- Executes the go() function -->

onload - The JavaScript code to be run when the document is loaded.


<audio onload="go()">Audio content here</audio>   <!-- Executes the go() function -->

onresize - The JavaScript code to be run when the browser window is resized.


<audio onresize="go()">Audio content here</audio>   <!-- Executes the go() function -->

onscroll - The JavaScript code to be run when the scrollbar of an element is being scrolled.


<audio onscroll="go()">Audio content here</audio>   <!-- Executes the go() function -->

onunload - The JavaScript code to be run once a page has unloaded or the browser window has been closed.


<audio onunload="go()">Audio content here</audio>   <!-- Executes the go() function -->

Document Element

oncopy - The JavaScript code to be run when the user copies the content of an element.


<audio oncopy="go()">Audio content here</audio>   <!-- Executes the go() function -->

oncut - The JavaScript code to be run when the user cuts the content of an element.


<audio oncut="go()">Audio content here</audio>   <!-- Executes the go() function -->

onpaste - The JavaScript code to be run when the user pastes some content into an element.


<audio onpaste="go()">Audio content here</audio>   <!-- Executes the go() function -->

Drag and Drop

ondrag - The JavaScript code to be run when an element is dragged.


<audio ondrag="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondragend - The JavaScript code to be run when an element has stopped being dragged.


<audio ondragend="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondragenter - The JavaScript code to be run when an element has been dragged to a valid drop target.


<audio ondragenter="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondragleave - The JavaScript code to be run when an element leaves a valid drop target.


<audio ondragleave="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondragover - The JavaScript code to be run when an element is being dragged over a valid drop target.


<audio ondragover="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondragstart - The JavaScript code to be run at the start of a drag operation.


<audio ondragstart="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondrop - The JavaScript code to be run when dragged element is being dropped.


<audio ondrop="go()">Audio content here</audio>   <!-- Executes the go() function -->

Form

onblur - The JavaScript code to be run on abort.


<audio onblur="go()">Audio content here</audio>   <!-- Executes the go() function -->

onchange - The JavaScript code to be run when object changed and attempt to leave field.


<audio onchange="go()">Audio content here</audio>   <!-- Executes the go() function -->

oncontextmenu - The JavaScript code to be run when a context menu is triggered.


<audio oncontextmenu="go()">Audio content here</audio>   <!-- Executes the go() function -->

onfocus - The JavaScript code to be run when the element gets focus.


<audio onfocus="go()">Audio content here</audio>   <!-- Executes the go() function -->

oninput - The JavaScript code to be run when an element gets user input.


<audio oninput="go()">Audio content here</audio>   <!-- Executes the go() function -->

oninvalid - The JavaScript code to be run when an element is invalid.


<audio oninvalid="go()">Audio content here</audio>   <!-- Executes the go() function -->

onreset - The JavaScript code to be run when the reset button of a form is clicked.


<audio onreset="go()">Audio content here</audio>   <!-- Executes the go() function -->

onselect - The JavaScript code to be run when some or all of the contents of an object are selected.


<audio onselect="go()">Audio content here</audio>   <!-- Executes the go() function -->

onsubmit - The JavaScript code to be run when a form is submitted.


<audio onsubmit="go()">Audio content here</audio>   <!-- Executes the go() function -->

Keyboard

onkeydown - The JavaScript code to be run when an element is in focus and keyboard key is pressed.


<audio onkeydown="go()">Audio content here</audio>   <!-- Executes the go() function -->

onkeypress - The JavaScript code to be run when an element is in focus and keyboard key is pressed down and released.


<audio onkeypress="go()">Audio content here</audio>   <!-- Executes the go() function -->

onkeyup - The JavaScript code to be run when an element is in focus and keyboard key is released.


<audio onkeyup="go()">Audio content here</audio>   <!-- Executes the go() function -->

Media

oncanplay - The JavaScript code to be run when a file has buffered enough so it is ready to start playing.


<audio oncanplay="go()">Audio content here</audio>   <!-- Executes the go() function -->

oncanplaythrough - The JavaScript code to be run when a file can be played all the way to the end without further need of buffering.


<audio oncanplaythrough="go()">Audio content here</audio>   <!-- Executes the go() function -->

oncuechange - The JavaScript code to be run when the cue changes when using the track element.


<audio oncuechange="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondurationchange - The JavaScript code to be run when the length of the media is changed.


<audio ondurationchange="go()">Audio content here</audio>   <!-- Executes the go() function -->

onemptied - The JavaScript code to be run when a media resource element suddenly becomes empty, usually due to an error.


<audio onemptied="go()">Audio content here</audio>   <!-- Executes the go() function -->

onended - The JavaScript code to be run when the media has reach the end.


<audio onended="go()">Audio content here</audio>   <!-- Executes the go() function -->

onloadeddata - The JavaScript code to be run when media data is loaded and playback can start.


<audio onloadeddata="go()">Audio content here</audio>   <!-- Executes the go() function -->

onloadedmetadata - The JavaScript code to be run when metadata has been loaded.


<audio onloadedmetadata="go()">Audio content here</audio>   <!-- Executes the go() function -->

onloadstart - The JavaScript code to be run when the media resource has started loading.


<audio onloadstart="go()">Audio content here</audio>   <!-- Executes the go() function -->

onpause - The JavaScript code to be run when the media resource has been paused.


<audio onpause="go()">Audio content here</audio>   <!-- Executes the go() function -->

onplay - The JavaScript code to be run when the media resource starts playback.


<audio onplay="go()">Audio content here</audio>   <!-- Executes the go() function -->

onplaying - The JavaScript code to be run when playback has already begun.


<audio onplaying="go()">Audio content here</audio>   <!-- Executes the go() function -->

onprogress - The JavaScript code to be run when the browser is fetching the media data.


<audio onprogress="go()">Audio content here</audio>   <!-- Executes the go() function -->

onratechange - The JavaScript code to be run when the playback rate changes.


<audio onratechange="go()">Audio content here</audio>   <!-- Executes the go() function -->

onseeked - The JavaScript code to be run when the seeking attribute is set to false indicating that seeking has finished.


<audio onseeked="go()">Audio content here</audio>   <!-- Executes the go() function -->

onseeking - The JavaScript code to be run hen the seeking attribute is set to true indicating that seeking is currently active.


<audio onseeking="go()">Audio content here</audio>   <!-- Executes the go() function -->

onstalled - The JavaScript code to be run when the browser is unable to continue fetching media data.


<audio onstalled="go()">Audio content here</audio>   <!-- Executes the go() function -->

onsuspend - The JavaScript code to be run when media data has stopped before being completely loaded.


<audio onsuspend="go()">Audio content here</audio>   <!-- Executes the go() function -->

ontimeupdate - The JavaScript code to be run when the media resources current playback position has changed.


<audio ontimeupdate="go()">Audio content here</audio>   <!-- Executes the go() function -->

onvolumechange - The JavaScript code to be run when the volume has changed or been muted.


<audio onvolumechange="go()">Audio content here</audio>   <!-- Executes the go() function -->

onwaiting - The JavaScript code to be run when the media resource has paused but is expected to resume.


<audio onwaiting="go()">Audio content here</audio>   <!-- Executes the go() function -->

Mouse

onclick - The JavaScript code to be run when a mouse is clicked on the element.


<audio onclick="go()">Audio content here</audio>   <!-- Executes the go() function -->

ondblclick - The JavaScript code to be run when a mouse is double clicked on the element.


<audio ondblclick="go()">Audio content here</audio>   <!-- Executes the go() function -->

onmousedown - The JavaScript code to be run when the mouse button is pressed down while the cursor is over the element.


<audio onmousedown="go()">Audio content here</audio>   <!-- Executes the go() function -->

onmousemove - The JavaScript code to be run when the mouse button is moved.


<audio onmousemove="go()">Audio content here</audio>   <!-- Executes the go() function -->

onmouseout - The JavaScript code to be run when the mouse cursor moves off an element.


<audio onmouseout="go()">Audio content here</audio>   <!-- Executes the go() function -->

onmouseover - The JavaScript code to be run when the mouse cursor moves over an element.


<audio onmouseover="go()">Audio content here</audio>   <!-- Executes the go() function -->

onmouseup - The JavaScript code to be run when the mouse button is released while the cursor is over the element.


<audio onmouseup="go()">Audio content here</audio>   <!-- Executes the go() function -->

onwheel - The JavaScript code to be run when the mouse wheel rolls up or down over an element.


<audio onwheel="go()">Audio content here</audio>   <!-- Executes the go() function -->

Window

NONE

go to home page Homepage go to top of page Top