Thẻ <video> HTML


Thí dụ

Phát 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>

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

Thẻ <video>được sử dụng để nhúng nội dung video vào tài liệu, chẳng hạn như một đoạn phim hoặc các luồng video khác.

Thẻ <video>chứa một hoặc nhiều <source>thẻ với các nguồn video khác nhau. Trình duyệt sẽ chọn nguồn đầu tiên mà nó hỗ trợ.

Văn bản giữa các thẻ <video></video> sẽ chỉ được hiển thị trong các trình duyệt không hỗ trợ phần tử <video>.

Có ba định dạng video được hỗ trợ trong HTML: MP4, WebM và OGG.

Browser MP4 WebM Ogg
Edge YES YES YES
Chrome YES YES YES
Firefox YES YES YES
Safari YES YES NO
Opera YES YES YES

Mẹo và lưu ý

Mẹo: Đối với các tệp âm thanh, hãy nhìn vào thẻ. <audio>



Hỗ trợ trình duyệt

Các số trong bảng chỉ định phiên bản trình duyệt đầu tiên hỗ trợ đầy đủ phần tử.

Element
<video> 4.0 9.0 3.5 3.1 11.5

Thuộc tính tùy chọn

Attribute Value Description
autoplay autoplay Specifies that the video will start playing as soon as it is ready
controls controls Specifies that video controls should be displayed (such as a play/pause button etc).
height pixels Sets the height of the video player
loop loop Specifies that the video will start over again, every time it is finished
muted muted Specifies that the audio output of the video should be muted
poster URL Specifies an image to be shown while the video is downloading, or until the user hits the play button
preload auto
metadata
none
Specifies if and how the author thinks the video should be loaded when the page loads
src URL Specifies the URL of the video file
width pixels Sets the width of the video player

Thuộc tính toàn cầu

Thẻ <video>cũng hỗ trợ Thuộc tính chung trong HTML .


Thuộc tính sự kiện

Thẻ <video>cũng hỗ trợ Thuộc tính sự kiện trong HTML .


Các trang liên quan

Tham chiếu DOM HTML: Tham chiếu DOM Audio / Video HTML


Cài đặt CSS mặc định

Không có.