How to create a clickable image valid for W3C?

Asked

Viewed 270 times

2

According to the reply of question I did here, the W3C discourages the use of a tag img within a link (<a>);

But this imposition of the W3C sounded a little controversial, because since I program for the Web I have done so, I have been taught to do so and I see many programmers doing so.

<a href="perfil.html"><img src="usuario.png"></a>

So, if we can’t create the image by merging "IMG into A", which is the alternative to creating a clickable link?

Javascript can’t be, right? If the W3C criticizes this practice, then what would be the alternative?

  • Well, I don’t agree @Guilhermeguini. W3C, from what I understand, deals with HTML coding. She couldn’t just suggest using Js. They have to give the solution to this

  • I was going to ask the same question, I even preferred it because I was curious about the right way to do it

  • I practically always did it the wrong way, I don’t know anything more kkkk

  • Guys, don’t worry. No one’s wrong, I’ll improve the answers

  • 1

    @Victorgomes look at the answer, really it is not wrong. It seems that there was a misunderstanding about what the answer meant. I apologize.

  • Great, I was looking about this possible "bad practice" and had found nothing, that good to know that we remain right haha

Show 1 more comment

1 answer

4


In fact, a small correction: When I asked the question, I misunderstood the answer that said IMG is not accepted within A.

According to W3C it is not recommended to use IMG as a daughter of a A when the tag IMG has the attribute usemap.

So there’s actually no problem using the Img within a A, is valid by W3C Validator (I ran the tests here).

Only features eros when we use usermap

Nessa Resposta in SOEN, we have the explanation about the elements that are not accepted by w3c within a <a>.

The Excerpt on img says the following:

<img> (if the usemap attribute is present)

Which translating is:

<img> (If the attribute usemap is present)

I apologize for the fright that some of you have been through, thinking you’ve been sneaking around!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.