2006
11.01

When using XHTML, the contents of <script> and <style> elements must be marked as CDATA. This is essential when serving XHTML correctly (as application/xhtml+xml).

When possible, use external script and style files and reference these from your XHTML document (behavioural and presentational separation). However, the examples below show how to place <script> and <style> inside your XHTML document correctly. This method should be compatible with older browsers, and therefore degrades gracefully.

Marking <script> as CDATA:

<script type="text/javascript">
  <!--//--><![CDATA[//><!--
    ......
  //--><!]]>
</script>

Marking <style> as CDATA:

<style type="text/css">
  <!--/*--><![CDATA[/*><!-- */
    ......
  /*]]>*/-->
</style>

ASP.NET 2.0

If you are serving ASP.NET pages as application/xhtml+xml (see Serving the Correct MIME Type for XHTML using ASP.NET 2.0), then the automatically generated JavaScript will not be marked as CDATA, and will therefore not work. For a workaround see: Marking ASP.NET 2.0 Generated JavaScript as CDATA.

2006
11.01

The aim of this article is to underline the importance of standards compliant web pages in promoting usability, compatibility, and accessibility – therefore allowing equal opportunity and equal access to content for all.

A History of Non-Compliance

When Netscape lost the "Browser Wars" in April 2002, Internet Explorer was in complete dominance of the web browser market – with a 96% share (source: OneStat.com). For web developers at the time, this meant that designing for Internet Explorer was all that mattered. The dominance of a single web browser led to a disregard for standards compliance.

  • Accessibility & usability problems when sites were accessed using other browsers.
  • Decreased efficiency due to increased file sizes, and website code not following a standard set of rules
  • Misuse of HTML as a design tool

The Benefits of Standards Compliance

The number of different ways to access the internet are increasing. Some of the less common user agents include:

  • Mobile phones
  • Televisions
  • Text-mode browsers
  • Text-to-speach synthesisers
  • Braille browsers
  • Robots (such as search engine spiders)

Standards compliance can be seen as a way to "future-proof" a website. New browsers will still correctly render websites constructed using past standards.

In the United Kingdom and Australia, accessibility is the law. The implementation of standards is a vital step towards accessibility. Accessibility benefits those with and without disabilities.

The use of standards is the only way to ensure that a website is accessible by all visitors, no matter how they access the web. By ensuring accessibility you are not neglecting any of your potential visitors.

Summary

Adherence to standards = a big step towards a functional, compatible, and accessible website.

Further Reading