Skip to content
学习 衡量 博客 Case studies 关于
本页内容
  • Lighthouse 图像替代文本审核为何失败
  • 编写有效 alt 文本的提示
  • 资源

图像元素没有 [alt] 属性

May 2, 2019 — 更新日期 Sep 19, 2019
Available in: Español, 한국어, Português, English
Appears in: 无障碍功能审核
本页内容
  • Lighthouse 图像替代文本审核为何失败
  • 编写有效 alt 文本的提示
  • 资源

信息元素适合简短的描述性替代文本。对于空 alt 属性,可以忽略装饰元素。

Lighthouse 图像替代文本审核为何失败 #

Lighthouse 标记没有 alt 属性的 <img> 元素:

显示 <img> 元素没有 alt 属性的 Lighthouse 审核
The Lighthouse Accessibility score is a weighted average of all the accessibility audits. See the Lighthouse accessibility scoring post for more information.

如何为图像添加替代文本 #

为每个 <img> 元素提供一个 alt 属性。如果图像加载失败,则会将 alt 文本作为占位符,这样,用户才能知道图像想要表达什么。(另请参阅包括图像和对象的替代文本。)

大多数图像都应有简短的描述性文本:

<img alt="Audits set-up in Chrome DevTools" src="...">

如果图像用作装饰,并且没有提供任何有用的内容,您可以给它一个空的 alt="" 属性,以便将其从可访问性树中删除:

<img src="background.png" alt="">
您还可以使用 ARIA 标签来描述图像,例如 <img aria-label="Audits set-up in Chrome DevTools" src="..."> 另请参阅使用 aria-label 属性和使用 aria-labelledby 属性。

编写有效 alt 文本的提示 #

  • alt 文本要体现图像的意图、目的和含义。
  • 盲人用户要从替代文本获得的信息要与视力正常的用户从图像获得的信息多少相同。
  • 避免使用“图表”、“图像”或“图形”等非特定词。

要了解更多信息,请参阅 WebAIM 的替代文本指南。

资源 #

  • 没有 [alt] 属性的图像元素审核的源代码
  • 图像必须有替代文本 (Deque University)
Last updated: Sep 19, 2019 — Improve article
Return to all articles
分享
订阅

Contribute

  • 提交错误
  • 查看源代码

相关内容

  • developer.chrome.com
  • Chrome 动态
  • 网站开发基础
  • 案例研究
  • 播客
  • 节目

连接

  • Twitter
  • YouTube
  • Google Developers
  • Chrome
  • Firebase
  • Google Cloud Platform
  • 所有产品
  • 条款和隐私权
  • 社区准则

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies.