Why is it that »
valid for an alt atribute but »
is not?
1 Answer
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.
-
-
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.– vdegenneCommented Nov 15, 2011 at 15:21
-
1I 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.– TobyCommented Nov 15, 2011 at 22:14