Is it possible to pass W3C XHTML strict validation and still use Google Analytics code on my webpage?

  • What errors do you get when you insert google analytics on your page? Commented Oct 14, 2010 at 11:48
  • 1
    You will probably get better answers at webmasters.stackexchange.com. This site is about using existing web apps, not managing your own web site.
    – ale
    Commented Oct 14, 2010 at 15:17

2 Answers 2


Yes, w3 xhtml strict validation does not check or see Javascript.

  • 1
    Presumably the <script> tags will need to be valid XHTML.
    – ale
    Commented Oct 14, 2010 at 15:15

The <script> tag in XHTML differs slightly from the one in HTML in that its content is of type (#PCDATA), which means that entities in the tag will be parsed. Thus most non-trivial code will break XHTML validation.

To make your <script> tag valid XHTML, use syntax like this:

<script type="text/javascript">//<![CDATA[
var i=10;
if (i<5) {
    // some code