HTML <source> 标签
标签" href="tag-main.html"><main>
<map>
<mark>
<menu>
<meta>
<meter>
<nav>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<html>
<picture>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<textarea>
< template>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
HTML <source> 标签
实例
带有两个源文件的音频播放器。浏览器需要选择它所支持的源文件(如果都支持则任选一个):
<audio controls>
<source src="horse.ogg" type="audio/ogg">
<source src="horse.mp3" type="audio/mpeg">
您的浏览器不支持 audio 元素。
</audio>
浏览器支持
表格中的数字表示支持该标签的第一个浏览器版本号。
| 标签 | |||||
|---|---|---|---|---|---|
| <source> | 4.0 | 9.0 | 3.5 | 4.0 | 10.5 |
标签定义及使用说明
<source> 标签为媒体元素(比如 <video> 和 <audio>)定义媒体资源。
<source> 标签允许您规定两个视频/音频文件供浏览器根据它对媒体类型或者编解码器的支持进行选择。
HTML 4.01 与 HTML5之间的差异
<source> 标签是 HTML5 中的新标签。
属性
New :HTML5 中的新属性。
| 属性 | 值 | 描述 |
|---|---|---|
| mediaNew | media_query | 规定媒体资源的类型,供浏览器决定是否下载。 |
| srcNew | URL | 规定媒体文件的 URL。 |
| type | MIME_type | 规定媒体资源的 MIME 类型。 |
| sizes | 不同页面布局设置不同图片大小。 | |
| srcset | URL | <source> 应用于 <picture> 标签时需要使用到。指定在不同情况下使用的图像 URL。 |
更多实例
实例
在 <video> 标签中使用 <source> 来设置视频:
<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>
实例
在 <picture> 标签中使用 <source> 来设置不同屏幕显示的图片:
<picture>
<source media="(min-width:650px)" srcset="https://static.jyshare.com/images/runoob-logo.png">
<source media="(min-width:465px)" srcset="https://static.jyshare.com/images/code-icon-script.png">
<img src="https://static.jyshare.com/images/mix/hjkg_icon.png" style="width:auto;">
</picture>
全局属性
<source> 标签支持 HTML 的全局属性。
事件属性
<source> 标签支持 HTML 的事件属性。