5

Why is it that » valid for an alt atribute but » is not?

1 Answer 1

4

It depends on your doctype. In HTML 4 and 5, using named entities like » is perfectly valid. However, in XHTML you must use numbered entities like » - most named entities are invalid, except for ", ', <, > and &.

Note: the alt tag is irrelevant in this case, it allows the same textual content as outside of HTML tags.

Simplest solution in my opinion: switch to the HTML5 doctype - <!DOCTYPE html>. It forces standards modes in all browsers, is future proof and is dead simple to remember.

5
  • Interestingly the site this appeared in is HTML5
    – Toby
    Commented Nov 15, 2011 at 15:16
  • In that case maybe it's a bug in the HTML5 validator; I believe it's still in beta at the moment. HTML5 itself is still changing regularly. Commented Nov 15, 2011 at 15:19
  • 2
    @Toby don't trust what's written behind the hood, trust the specifications.
    – vdegenne
    Commented Nov 15, 2011 at 15:21
  • 1
    I just checked the HTML5 spec for the img element and couldn't see anything specifying the format of alt text. Commented Nov 15, 2011 at 15:25
  • @Oddant there is an argument though that in practice you need to trust how the browsers implement it - in an ideal world though, yes I would agree.
    – Toby
    Commented Nov 15, 2011 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.