Data-title/data-original-title attributes and acce

2019-07-04 14:08发布

问题:

I have been searching for information about the attributes data-title and data-original-title. My issue is that Twitter Bootstrap converts the title-attribute into a data-original-title and I am not sure that this is what I want. What about screen readers for instance? Do they treat the data-title as a title, or do they ignore it? If I use one of those data-attributes, do I have to add a title-attribute as well?

回答1:

The custom data-* attributes are defined for HTML5. They are "intended to store custom data private to the page or application".

The spec says:

These attributes are not intended for use by software that is independent of the site that uses the attributes.

So other tools (like screen readers) should not make use of them.

If something is a title, you should not use a data-* attribute (like data-title) in the first place, as the spec says "[…] for which there are no more appropriate attributes or elements"; use title.