marcusstarnes
marcusstarnes

Reputation: 6531

Should meta tags be HTML-encoded?

I generally HTML-encode any user generated content that I render on my website, so ampersands become & and so on. I was wondering if this should be done (from a standards point of view) to any dynamically generated meta tag throughout a site?

Upvotes: 26

Views: 10357

Answers (3)

BoltClock
BoltClock

Reputation: 723598

If you mean something like this:

<meta name="description" content="Some stuff, other stuff &amp; even more stuff!" />

Yes, you need to encode the ampersand, and other special characters, to entities so your meta tags validate.

Upvotes: 18

meder omuraliev
meder omuraliev

Reputation: 186562

Yes. So for example quotes don't close the content attribute for a meta element which would trigger invalid HTML.

Upvotes: 4

Sean Reilly
Sean Reilly

Reputation: 21836

Absolutely. All content within the HTML document must be encoded this way.

Upvotes: 27

Related Questions