HTMLsrc属性_
定義と使用法
このsrc
属性は、外部リソースの場所(URL)を指定します。
に適用されます
このsrc
属性は、次の要素で使用できます。
要素 | 属性 |
---|---|
<オーディオ> | src |
<埋め込み> | src |
<iframe> | src |
<img> | src |
<入力> | src |
<スクリプト> | src |
<ソース> | src |
<トラック> | src |
<ビデオ> | src |
例
オーディオの例
オーディオプレーヤー:
<audio src="horse.ogg" controls>
Your browser does not support the audio element.
</audio>
埋め込み例
埋め込まれたフラッシュアニメーション:
<embed src="helloworld.swf">
Iframeの例
最も単純な使用法の<iframe>:
<iframe src="/default.asp"></iframe>
Imgの例
画像は次のようにマークアップされます。
<img src="smiley.gif" alt="Smiley face">
入力例
送信ボタンを表す画像を含むHTMLフォーム:
<form action="/action_page.php">
First name: <input type="text" name="fname"><br>
<input type="image" src="submit.gif" alt="Submit">
</form>
スクリプトの例
外部JavaScriptファイルをポイントします。
<script src="myscripts.js"></script>
ソースの例
2つのソースファイルを備えたオーディオプレーヤー。ブラウザは、サポートしているファイル(ある場合)を選択する必要があります。
<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>
トラック例
2つの字幕トラックを含むビデオ:
<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>
ビデオの例
ビデオを再生する:
<video src="movie.ogg" controls>
Your browser does not support the video tag.
</video>
ブラウザのサポート
このsrc
属性では、要素ごとに次のブラウザがサポートされています。
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 |