alt 属性は、何らかの理由(接続が遅い、src 属性に誤りがある、ユーザーがスクリーンリーダを使用している)で、ユーザが画像を見ることができない場合、 alt 属性はその画像の代替情報を提供するするものです。
注: alt 属性は、<img> 要素には必須です。
注: <input> 要素の場合、alt 属性は <input type="image"> でのみ使用できます。
チップ: 画像のツールチップを作成するには、title 属性を使用してください!
alt 属性は、以下の要素で使用することができます:
要素 | 属性 |
---|---|
<area> | alt |
<img> | alt |
<input> | alt |
クリック可能な領域を持つイメージ・マップ:
<img src="planets.gif"
width="145" height="126"
alt="Planets"
usemap="#planetmap">
<map
name="planetmap">
<area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun">
<area shape="circle" coords="90,58,3" href="mercur.htm" alt="Mercury">
<area shape="circle" coords="124,58,8" href="venus.htm" alt="Venus">
</map>
Try it Yourself ❯
送信ボタンを表す画像付きの HTMLフォーム:
<form action="demo_form.html">
First name: <input type="text" name="fname"><br>
<input type="image" src="submit.gif" alt="Submit" width="48" height="48">
</form>
Try it Yourself ❯
alt
属性は、要素ごとに次の通りブラウザによりサポートされています。属性は、要素ごとに以下のブラウザがサポートしています。
要素 | |||||
---|---|---|---|---|---|
area | Yes | Yes | Yes | Yes | Yes |
img | Yes | Yes | Yes | Yes | Yes |
input | Yes | Yes | Yes | Yes | Yes |