Latest web development tutorials

HTML audio src attribute

HTML audio tag Reference Manual HTML <audio> tag

Examples

Audio playback:

<audio src="horse.ogg" controls>
您的浏览器不支持 audio 元素。
</audio>

try it"

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

Internet Explorer 9+, Firefox, Opera, Chrome, and Safari browsers support the src attribute. . But not some browsers support the audio file format.

Note: Internet Explorer 8 and earlier versions of IE do not support the <audio> tag.


Definition and Usage

src attribute describes the audio file address (URL).

Ogg audio file format, can be played in Firefox, Opera and Chrome.

If you need to play audio in Internet Explorer and Safari browsers, you must use the MP3 file.

If you need to be compatible with all browsers - use the <audio> element in the <source> element. <Source> elements can link to different audio files. The browser will use the first recognized audio file format.

Examples

<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
您的浏览器不支持 audio 元素。
</audio>

try it"


Differences between HTML 4.01 and HTML5

<Audio> tag HTML5 is new.


grammar

<audio src="URL">

Property Value

描述
URL

规定音频/视频来源的 URL。

可能的值:

  • 绝对 URL - 指向另一个网站(比如 src="http://example.com/movie.ogg")
  • 相对 URL - 指向网站内的某个文件(比如 src="/data/movie.ogg")


HTML audio tag Reference Manual HTML <audio> tag