Inline SVG lt;titlegt; lt;descgt; correct usage for accessilibility(内联 SVG lt;标题gt;lt;描述gt;可访问性的正确用法)
问题描述
我在我的 html 中使用了很多内联 svg,但对于在可访问性方面呈现它们的最佳方式有点困惑.
I am using a lot of inline svgs in my html and am a little confused about the best way to present them concerning accessibility.
我看到了两种将 <title>
和 <desc>
添加到 svgs 的方法 -
I've see two methods to add <title>
and <desc>
to svgs -
<svg role="img" aria-label="[title + description]">
<title>title text here</title>
<desc>a description of the image here</desc>
<path> etc.
</svg>
<svg role="img" aria-labelledby="my_svg_title my_svg_description">
<title id="my_svg_title">title text here</title>
<desc id="my_svg_description">a description of the image here</desc>
<path> etc.
</svg>
第一种方法似乎是最好的,因为我不必为每个标题和描述提供唯一的 ID(我每页有多个 svg)?是这样吗?选择aria-label"或aria-labelledby"时还有什么需要考虑的吗?
The first method seems the best as I don't have to give unique IDs to each title and description (I have multiple svgs per page)? Is that the case? Is there anything else to take into consideration when choosing "aria-label" or "aria-labelledby"?
另外,我对这个角色还有点困惑 <desc > 播放 - 它与 alt 完全相同吗?我总是从内联 svgs 中删除 xmlns 和 xmlns:xlink 标签以进行优化,谷歌图像搜索是否仍会将这些内联 svgs 引用为图像?<desc>
会帮忙吗?
Also I am still confused a little about the role < desc > plays - is it exactly the same as alt? I always remove the xmlns and xmlns:xlink tags from inline svgs for optimisation, will google image search still reference these inline svgs as images? Will <desc>
help with that?
如果内联 svg 将始终显示(内联 svg 是否永远不会呈现?),那么 <desc>
将永远不会对丢失的图像有用,这只会让页面阅读器具有可访问性,这可能用它.是吗?
If the inline svg will always display (do inline svgs ever not render?) then the <desc>
will never be useful for missing images, which then only leaves page readers for accessibility which could use it. Do they?
基本上值得使用/包含<desc>
吗?
Basically is it worth using/including <desc>
?
推荐答案
想想
就像alt
,想想
喜欢 <figcaption>
Think of <title>
like alt
, think of <description>
like <figcaption>
您的 <title>
应充分描述图像,以便用户了解图像包含的内容.
Your <title>
should describe the image sufficiently to provide a user with an understanding of what the image contains.
如果它是一个复杂的图像,或者图像在需要更多细节的文章中起着至关重要的作用,则使用 <description>
.
If it is a complex image, or the image plays a vital role in an article that necessitates more details then use <description>
.
Deque 对不同的方法做了很好的测试,发现你的第二个版本是最可靠的,其中 title
和 description
通过 aria-labelledby
和 ID 链接,所以使用它.
Deque did a great test of different methods and found that your second version was the most reliable with a title
and description
linked via aria-labelledby
and IDs, so use that.
是的,谷歌仍然会将它们引用为没有 xmlns
内联提供的图像(前提是您将页面作为 mime 类型 text/html
提供,否则您将遇到渲染问题).对于外部图像,我会保留它,这是一个很小的优化,不值得.
Yes google will still reference them as images without xmlns
served inline (provided you serve your page as mime type text/html
otherwise you will get rendering issues). For external images I would leave it in, it is such a minor optimisation it isn't worth it.
据我所知,内嵌 SVG 在 Google 图像搜索中没有被编入索引(但它们的内容仍然有助于您在 Google 搜索算法中的 SEO,因此仍然值得拥有 <description>
在适当的地方.)
Inline SVGs do not get indexed as far as I am aware in Google Image Search (but their content still contributes to your SEO in Google Search Algorithms slightly so it is still worth having <description>
where appropriate.)
如果内联,SVG 将始终呈现(假设浏览器支持 SVG,这很有可能).
SVGs will always render if inline (assuming the browser supports SVG which is very likely).
是的,如果图像足够复杂以至于您无法用 <title>
在 20 个字或更少的字数内描述它,则包括 <desc>
(一般规则).
Yes include <desc>
if the image is sufficiently complex that you can't describe it with <title>
in 20 words or less (general rule).
最后的想法 - alt
标签、titles
等都是关于可访问性的,不要担心它们的 SEO 关键字,因为你会最终损害可用性.我知道你没有提到,但为了清楚起见,我想我会把它放在这里.
final thought - alt
tags, titles
etc. are all about accessibility, don't worry about them for SEO keywords as you will end up damaging usability. I know you didn't mention that but I thought I would put it in here for clarity.
p.s. - 下一次,可能一次限制为 1 或 2 个问题,因为要回答的问题很多!
p.s. - Next time, maybe limit this to 1 or 2 questions at once as that was a lot to answer!
这篇关于内联 SVG <标题><描述>可访问性的正确用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:内联 SVG <标题><描述>可访问性的正确用法
基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01