Is it OK to have an empty anchor tag?

前端 未结 5 1162
庸人自扰
庸人自扰 2021-01-11 19:02

I know that I can do the following if I want to turn an image into a click-able link:



        
相关标签:
5条回答
  • 2021-01-11 19:24

    It is not OK at all, since it breaks fundamental accessibility principles. There is no way to specify alternative text for a background image, the same way you can and should specify it using an alt attribute in an img tag for a content image. See WCAG 2.0 Guideline 1.1.

    If you wish to change an image on mouseover, there are CSS and JavaScript techniques for that.

    0 讨论(0)
  • 2021-01-11 19:33

    It's valid, but it's best if you did put something in there and used something like

    font-size: 0;
    

    to hide it away. This way, if someone does not have CSS (screen readers for example), he would still be able to tell approximately what the link is about.

    Here's a great article on the subject

    0 讨论(0)
  • 2021-01-11 19:44

    It is perfectly valid, but if you want, you can put a blank space inside:  

    0 讨论(0)
  • 2021-01-11 19:44

    Over at Markup.tips we recently did some accessibility testing in iOS 8 and discovered that VoiceOver will not navigation to empty links. There must at least be a non-breaking space. Whether this should be considered an iOS bug or not we are not sure.

    0 讨论(0)
  • 2021-01-11 19:47

    Use   as the text, and you are good.

    0 讨论(0)
提交回复
热议问题