HTML: Audio Tag

By Xah Lee. Date: . Last updated: .

what is Audio Tag

audio tag lets you embed a audio file.

Example

Here is what your browser shows.

Code

<audio src="i/s/test.m4a" controls></audio>

Attributes

Following are the most useful optional attributes.

controls

show audio player controls.

Boolean attribute. Does not take any value.

if not on, the entire audio tag is invisible.

autoplay

Boolean attribute. Does not take any value.

loop

Boolean attribute. Does not take any value.

preload

values is one of

  • auto → default. means browser decides.
  • metadata
  • none

Test Your Browser

Here is different audio formats, using audio tag.

test.m4a
coi.mp3
test.oga

Audio Formats Browser Support

audio format support 2018-11-14
format/browserChromeSafariFirefoxEdge
.m4a (aka acc)yesyesyesyes
.mp3yesyesyesyes
.opusyesnoyesyes
.oggyesnoyesyes

midi file is not supported by any browser, as of 2018-11-14.

Audio tag is displayed inline by default

Audio tag is displayed inline by default. That is, it flows like text.

you can change to to block.

audio {
display: block;
}

HTML Video and Audio Tags