Thuộc tính HTML src


Định nghĩa và Cách sử dụng

Thuộc srctính chỉ định vị trí (URL) của tài nguyên bên ngoài.


Áp dụng đối với

Thuộc srctính có thể được sử dụng trên các phần tử sau:

Các yếu tố Thuộc tính
<audio> src
<embed> src
<iframe> src
<img> src
<input> src
<script> src
<nguồn> src
<nhạc phim> src
<video> src

Các ví dụ

Ví dụ về âm thanh

Trình phát âm thanh:

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

Ví dụ nhúng

Một hoạt ảnh flash được nhúng:

<embed src="helloworld.swf">

Ví dụ về iframe

Một <iframe> trong cách sử dụng đơn giản nhất:

<iframe src="/default.asp"></iframe>

Ví dụ về Img

Một hình ảnh được đánh dấu như sau:

<img src="smiley.gif" alt="Smiley face">

Ví dụ đầu vào

Biểu mẫu HTML có hình ảnh đại diện cho nút gửi:

<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  <input type="image" src="submit.gif" alt="Submit">
</form>

Ví dụ về tập lệnh

Trỏ đến tệp JavaScript bên ngoài:

<script src="myscripts.js"></script>

Ví dụ nguồn

Một trình phát âm thanh với hai tệp nguồn. Trình duyệt nên chọn tệp (nếu có) mà nó hỗ trợ:

<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>

Theo dõi ví dụ

Một video có hai phụ đề:

<video width="320" height="240" controls>
  <source src="forrest_gump.mp4" type="video/mp4">
  <source src="forrest_gump.ogg" type="video/ogg">
  <track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
  <track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>

Ví dụ về Video

Phát video:

<video src="movie.ogg" controls>
  Your browser does not support the video tag.
</video>

Hỗ trợ trình duyệt

Thuộc srctính này có hỗ trợ trình duyệt sau cho từng phần tử:

Element
audio 4.0 9.0 3.5 4.0 10.5
embed Yes Yes Yes Yes Yes
iframe Yes Yes Yes Yes Yes
img Yes Yes Yes Yes Yes
input 1.0 2.0 1.0 1.0 1.0
script Yes Yes Yes Yes Yes
source 4.0 9.0 3.5 4.0 10.5
track 18.0 10.0 31.0 6.0 15.0
video 4.0 9.0 3.5 4.0 10.5