[英]Screen reader NVDA read image title and alt. Need that the reader read only title and ignore alt
I have an image element with title and alt attributes that is required for SEO optimization.我有一个 SEO 优化所需的带有 title 和 alt 属性的图像元素。 But when the user hovers over the image.
但是当用户将鼠标悬停在图像上时。 The screen reader (NVDA) reads the image and alt text even if they have the same text.
屏幕阅读器 (NVDA) 会读取图像和替代文本,即使它们具有相同的文本。 I need to find a way to make the screen reader ignore one of them especially alt.
我需要找到一种方法让屏幕阅读器忽略其中一个,尤其是 alt。 Does anyone know a solution?
有谁知道解决方案? Thanks
谢谢
<img
className={className}
src={src}
alt={alt}
title={title}
loading="lazy"
{...props}
/>
You generally shouldn't have an alt
attribute and a title
attribute on the same image.您通常不应该在同一张图片上同时拥有
alt
属性和title
属性。 It's not invalid, but it doesn't make much logical sense, considering that they do many of the same things.这不是无效的,但考虑到他们做许多相同的事情,它没有多大逻辑意义。 Many browser/screen-readers will also read both, one after the other, which can be a less than ideal experience.
许多浏览器/屏幕阅读器也会一个接一个地阅读两者,这可能是一种不太理想的体验。
There is a visual component to title
where it will appear on hover (which alt
doesn't have), but it's not usually clear which elements can be hovered over to produce a tooltip and which can't.有一个可视化的组件
title
,它会在悬停时出现( alt
没有),但通常不清楚哪些元素可以悬停以产生工具提示,哪些不能。
It's also worth noting that title
is made for advisory information, whereas alt
is made for a textually equivalent description of an image.还值得注意的是,
title
是为咨询信息而制作的,而alt
是为图像的文本等效描述而制作的。
For these reasons, I think it's usually best to just avoid the title
attribute unless you have some really good reason to be using it and use alt
instead.由于这些原因,我认为通常最好避免使用
title
属性,除非您有充分的理由使用它并使用alt
代替。 I would remove the title
attribute on your image since alt
takes precedence in the accessible name computation .我会删除图像上的
title
属性,因为alt
在可访问名称计算中具有优先权。
If you really want to, you can remove alt
and just have the title
attribute.如果你真的想,你可以删除
alt
并只拥有title
属性。 It's not typically the done thing, and some automated checkers may complain about this, but it is valid HTML.这通常不是完成的事情,一些自动检查器可能会抱怨这一点,但它是有效的 HTML。
It's also worth mentioning that alt
and title
aren't SEO attributes.还值得一提的是
alt
和title
不是 SEO 属性。 You may be doing these things as part of an SEO review, but these attributes are designed for accessibility.您可能会将这些事情作为 SEO 审查的一部分,但这些属性是为可访问性而设计的。 If search engines can also benefit from them, then so be it.
如果搜索引擎也可以从中受益,那就这样吧。 At the end of the day, both SEO and accessibility are about making things machine-readable.
归根结底,SEO 和可访问性都是为了让机器可读。
You should remove the title and use only alt.您应该删除标题并仅使用 alt。
All screen readers handle alt and title differently.所有屏幕阅读器都以不同的方式处理 alt 和 title。 They all read alt, but when title is also present, their behavior differs and in fact it's configurable (for example Jaws allow to configure that).
它们都读取 alt,但是当 title 也存在时,它们的行为会有所不同,实际上它是可配置的(例如 Jaws 允许配置它)。
This is the reason why using title is discouraged, as it's impossible to know exactly what will actually be read.这就是为什么不鼓励使用 title 的原因,因为不可能确切地知道实际阅读的内容。 The alt attribute is the only reliable alternative text to use.
alt 属性是唯一可以使用的可靠替代文本。
Additionally, forget about all that SEO thing.此外,忘记所有那些搜索引擎优化的事情。 No one really knows if what you do has any influence.
没有人真正知道你的所作所为是否有任何影响。 This is always pure speculations.
这始终是纯粹的猜测。 Think first about users before thinking about machines.
在考虑机器之前先考虑用户。
you can add aria-hidden="true", if alt and title both are present如果 alt 和 title 都存在,您可以添加 aria-hidden="true"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.