Tag <sumber> HTML


Contoh

Pemutar audio dengan dua file sumber. Browser akan memilih <source> pertama yang didukungnya:

<audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

Lebih banyak contoh "Coba Sendiri" di bawah ini.


Definisi dan Penggunaan

Tag <source>digunakan untuk menentukan beberapa sumber daya media untuk elemen media, seperti <video> , <audio> , dan <picture> .

Tag <source>memungkinkan Anda untuk menentukan file video/audio/gambar alternatif yang dapat dipilih browser, berdasarkan dukungan browser atau lebar viewport. Browser akan memilih yang pertama <source> didukungnya.


Dukungan Peramban

Angka-angka dalam tabel menentukan versi browser pertama yang sepenuhnya mendukung elemen tersebut.

Element
<source> 4.0 9.0 3.5 4.0 10.5

Atribut

Attribute Value Description
media media_query Accepts any valid media query that would normally be defined in a CSS
sizes   Specifies image sizes for different page layouts
src URL Required when <source> is used in <audio> and <video>. Specifies the URL of the media file
srcset URL Required when <source> is used in <picture>. Specifies the URL of the image to use in different situations
type MIME-type Specifies the MIME-type of the resource


Atribut Global

Tag <source>juga mendukung Atribut Global dalam HTML .


Atribut Acara

Tag <source>juga mendukung Atribut Peristiwa dalam HTML .


Lebih Banyak Contoh

Contoh

Gunakan <source> dalam <video> untuk memutar video:

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

Contoh

Gunakan <source> dalam <picture> untuk menentukan gambar yang berbeda berdasarkan lebar viewport:

<picture>
  <source media="(min-width:650px)" srcset="img_pink_flowers.jpg">
  <source media="(min-width:465px)" srcset="img_white_flower.jpg">
  <img src="img_orange_flowers.jpg" alt="Flowers" style="width:auto;">
</picture>

Halaman Terkait

Tutorial HTML: Video HTML

Tutorial HTML: Audio HTML

Referensi DOM HTML: Objek Sumber


Pengaturan CSS Default

Tidak ada.