HTML alt 属性
定义和用法
alt 属性在用户因故无法查看图像时(例如,由于连接速度慢、src 属性出错或用户使用屏幕阅读器),提供图像的替代信息。
注意:<img> 元素需要 alt 属性。
注意:对于 <input> 元素,alt 属性只能与 <input type="image"> 一起使用。
提示:要为图像创建工具提示,请使用 title 属性!
适用范围
alt 属性可用于以下元素:
元素 | Attribute |
---|---|
<area> | alt |
<img> | alt |
<input> | alt |
示例
Area 示例
一个图像地图,带有可点击的区域
<img src="planets.gif" width="145" height="126" alt="行星"
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>
自己动手试一试 »
Input 示例
一个带有图片作为提交按钮的 HTML 表单
<form action="/action_page.php">
名:<input type="text" name="fname"><br>
<input type="image" src="submit.gif" alt="提交" width="48" height="48">
</form>
自己动手试一试 »
浏览器支持
alt 属性对每个元素的浏览器支持情况如下:
元素 | |||||
---|---|---|---|---|---|
area | 是 | 是 | 是 | 是 | 是 |
img | 是 | 是 | 是 | 是 | 是 |
input | 是 | 是 | 是 | 是 | 是 |