views:

39

answers:

4

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"&gt;
<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 '&amp;' instead?

Just as an example:

 <title>Dolce & Gabbana</title>
             or
 <title>Dolce &amp; Gabbana</title>

I can't use the word 'and' simply because it doesn't "look" as good.

Thanks

A: 

In my opinion, a hypen '-' works better. Nobody's gonna search with an ampersand symbol anyway.

Ruel
+1  A: 

run you page through http://validator.w3.org/ and follow the suggestions

Grumpy
A: 

The & symbol is invalid in HTML except as part of an entity (such as &amp;).

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.

Spudley
-1 You’re wrong. It is valid in this case.
Gumbo
@Gumbo - the w3c validator disagrees with you. (assuming strict mode, as per the question)
Spudley
Invalid in HTML4, valid in HTML5.
Matthew Wilson
bobince
@Spudley: It is valid. Just try it on your own using the [W3C Validator in fragment mode](http://validator.w3.org/#validate_by_input+with_options): It selects Strict automatically and the only error is that `title` is not allowed in the context (since it’s only a fragment).
Gumbo
@Gumbo (and others) - okay, I saw 'strict' in the doctype in the question and assumed 'xhtml'. My bad. In strict xhtml, the validator does indeed throw it as an error. For other doctypes, it's valid.... but still better to use the entity.
Spudley
+2  A: 

In this case both &amp; 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 &amp; to avoid ambiguity:

Authors should use "&amp;" (ASCII decimal 38) instead of "&" to avoid confusion with the beginning of a character reference (entity reference open delimiter). Authors should also use "&amp;" in attribute values since character references are allowed within CDATA attribute values.

See my answer on Do I really need to encode '&' as '&amp;'? for further information.

Gumbo