HTML Audio & Video

HTML DOM Audio/Video Complete Reference

This complete reference lists the properties, methods and events shared by the HTML <audio> and <video> elements. Both elements implement the HTMLMediaElement interface, so almost every member below works identically for sound and for video; the <video> element simply adds a few extra members such as videoWidth, videoHeight, width and height.


Overview

You access these members on any media element you obtain with document.getElementById(), create with new Audio(), or build with document.createElement("video"). Properties get or set state, methods perform actions, and events let you react to changes during loading and playback.

Properties

NameDescription
audioTracksReturns an AudioTrackList of the available audio tracks
autoplayGets/sets whether playback starts as soon as the media is ready
bufferedReturns a TimeRanges object of the buffered (downloaded) portions
controllerReturns the MediaController that groups this element (if any)
controlsGets/sets whether the browser's default controls are shown
crossOriginGets/sets the CORS settings for the media resource
currentSrcReturns the absolute URL of the currently selected media source
currentTimeGets/sets the current playback position in seconds
defaultMutedGets/sets the default (attribute) muted state
defaultPlaybackRateGets/sets the default playback speed
durationReturns the total length of the media in seconds
endedReturns whether playback has reached the end
errorReturns a MediaError object for the most recent error, or null
loopGets/sets whether the media restarts when it ends
mediaGroupGets/sets the name of the media group the element belongs to
mutedGets/sets whether sound is currently muted
networkStateReturns the current network state of the element
pausedReturns whether the media is currently paused
playbackRateGets/sets the current playback speed (1.0 = normal)
playedReturns a TimeRanges object of the portions that have been played
preloadGets/sets a hint for how much media to preload (none/metadata/auto)
readyStateReturns the current readiness state of the media
seekableReturns a TimeRanges object of the seekable portions
seekingReturns whether the browser is currently seeking
srcGets/sets the URL of the media resource
textTracksReturns a TextTrackList of the available text tracks (captions)
videoTracksReturns a VideoTrackList of the available video tracks
volumeGets/sets the audio volume, from 0.0 to 1.0
videoWidth(video only) Returns the intrinsic width of the video in pixels
videoHeight(video only) Returns the intrinsic height of the video in pixels
width(video only) Gets/sets the displayed width of the element
height(video only) Gets/sets the displayed height of the element
poster(video only) Gets/sets the poster image shown before playback

Methods

NameDescription
addTextTrack()Adds a new text track (for captions or subtitles) to the media
canPlayType()Reports whether the browser can likely play a given media type
fastSeek()Seeks quickly to a time, trading precision for speed
load()Re-loads the media element and resets it to its initial state
pause()Pauses playback of the media
play()Starts or resumes playback and returns a Promise

Events

NameDescription
abortFires when loading of the media is aborted
canplayFires when the browser can start playing the media
canplaythroughFires when the browser can play through without buffering
durationchangeFires when the duration of the media changes
emptiedFires when the media has become empty (e.g. after load errors)
endedFires when playback reaches the end of the media
errorFires when an error occurs while loading the media
loadeddataFires when the first frame of the media has loaded
loadedmetadataFires when duration and dimensions metadata have loaded
loadstartFires when the browser starts looking for the media
pauseFires when playback is paused
playFires when playback starts or resumes
playingFires when playback is ready to start after buffering
progressFires periodically as the browser downloads the media
ratechangeFires when the playback speed changes
seekedFires when a seek operation completes
seekingFires when a seek operation begins
stalledFires when the browser is trying to fetch data but none arrives
suspendFires when media data loading has been suspended
timeupdateFires when the current playback position changes
volumechangeFires when the volume or muted state changes
waitingFires when playback pauses to buffer more data
ℹ️

Members marked "(video only)" belong to HTMLVideoElement. All other rows are inherited from HTMLMediaElement and work on both <audio> and <video> elements.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships