I am about to finish up my dynamic classifieds website (php) and have some problem with figuring out how to write the meta and title tags.
I have read mixed articles about the &
sign, and how to use it in the title or meta tags properly.
What role does the document encoding have and does the DOCTYPE have anything to do with this also?
In my case, this is my document top:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
I wonder, should I write the and tags with an '&
' or an '&
' instead?
Just as an example:
<title>Dolce & Gabbana</title>
or
<title>Dolce & Gabbana</title>
I can't use the word 'and' simply because it doesn't "look" as good.
Thanks
In this case both &
and even just &
are valid as the latter is followed by a whitespace and thus cannot be confused with a reference open delimiter.
But the HTML 4 specification recommends to use &
to avoid ambiguity:
Authors should use "
&
" (ASCII decimal 38) instead of "&
" to avoid confusion with the beginning of a character reference (entity reference open delimiter). Authors should also use "&
" in attribute values since character references are allowed within CDATA attribute values.
See my answer on Do I really need to encode '&
' as '&
'? for further information.
In my opinion, a hypen '-' works better. Nobody's gonna search with an ampersand symbol anyway.
run you page through http://validator.w3.org/ and follow the suggestions
The &
symbol is invalid in HTML except as part of an entity (such as &
).
That kinda answers your question -- your first example is invalid HTML, so you should be using the second.
Most browsers will cope with the first example, as there's no ambiguity, but you should still be using the entity code if you're aiming to produce good code.