Tag HTML <audio>
Esempio
Riproduci un file audio:
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
Definizione e utilizzo
Il <audio>
tag viene utilizzato per incorporare contenuti audio in un documento, come musica o altri flussi audio.
Il <audio>
tag contiene uno o più
<source>
tag con diverse sorgenti audio. Il browser sceglierà la prima fonte che supporta.
Il testo tra i tag <audio>
e </audio>
verrà visualizzato solo nei browser che non supportano l' <audio>
elemento.
Ci sono tre formati audio supportati in HTML: MP3, WAV e OGG.
Formato audio e supporto del browser
Browser | MP3 | WAV | OGG |
---|---|---|---|
Edge / IE | YES | YES* | YES* |
Chrome | YES | YES | YES |
Firefox | YES | YES | YES |
Safari | YES | YES | NO |
Opera | YES | YES | YES |
*Dal bordo 79
Suggerimenti e note
Suggerimento: per i file video, guarda il tag.
<video>
Supporto browser
I numeri nella tabella specificano la prima versione del browser che supporta completamente l'elemento.
Element | |||||
---|---|---|---|---|---|
<audio> | 4.0 | 9.0 | 3.5 | 4.0 | 11.5 |
Attributi
Attribute | Value | Description |
---|---|---|
autoplay | autoplay | Specifies that the audio will start playing as soon as it is ready |
controls | controls | Specifies that audio controls should be displayed (such as a play/pause button etc) |
loop | loop | Specifies that the audio will start over again, every time it is finished |
muted | muted | Specifies that the audio output should be muted |
preload | auto metadata none |
Specifies if and how the author thinks the audio should be loaded when the page loads |
src | URL | Specifies the URL of the audio file |
Attributi globali
Il <audio>
tag supporta anche gli attributi globali in HTML .
Attributi dell'evento
Il <audio>
tag supporta anche gli attributi dell'evento in HTML .
Pagine correlate
Riferimento DOM HTML: Riferimento DOM audio/video HTML
Impostazioni CSS predefinite
Nessuno.