Electric Type

Multimedia

About Us

News

Help

XHTML Overview

Page 5 — Document Types and Character Sets

Document types have been a part of HTML for a long time, but few developers use them even though they are required in order to be compliant. XHTML is no different, and an additional XML tag can, and usually should, be used. Section 3.1.1 "Strictly Conforming Documents", of the XHTML 1.0 specification describes this in detail, so read the chapter for a complete overview.

Usually, your document type declaration will look something like this:


       <?xml version="1.0" encoding="iso-8859-1"?>
       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The URL above links to the W3C's copy of the XHTML 1.0 Document Type Definition. I figured this would be helpful, as most of us do not keep a copy of the XHTML 1.0 DTD laying around. Consult section 3.1.1 of the XHTML 1.0 specification for the document type that allow frame sets, or strict XHTML.

When declaring document types, you can omit the <?xml...?> tag, but you have to be careful if you choose do so. The default character set in XHTML is Unicode's UTF-8 or UTF-16. Until browsers catch up, it is best to specify what character set you are using both in the document type definition and using a <meta.../> tag. If you are using the above document type definition format, you should should also put the following in your XHTML header:

      <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1" />

Notice that I closed the <meta> tag!

Since we are not dealing with a standardized Web, some browser-Web server combinations are incompatible with the <?xml...?> tag. If you find that a simple XHTML document you have written that uses the <?xml...?> tag does not work with Internet Explorer, omit the the XML tag and use your <meta> tag to declare the UTF-8 character set. Luckly, UTF-8 is backward-compatible with the ASCII character set.

Use a <meta> tag like this one:

    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

If you need to do it this way, it's a wise decision to only use 7-bit ASCII characters in your document! To display any of the characters beyond the scope of ASCII, you will have to use entities.

For example, you shouldn't type

tête-à-tête,

but rather

t&ecirc;te-&agrave;-t&ecirc;te

UTF-8 is not compatible with any ISO 8859 character sets, so make sure you only use ASCII characters and entities if you cannot include the <?xml...?> tag.

next page»


Dynamic HTML  

Frames  

HTML Basics  

Stylesheets  

Tables  

XML  

Javascript  

Database Connections  

Intro To Perl  

HTML 4.0  

User Blogs

Screen Shots

Latest Updates

Contact Us

Valid HTML 4.01!
Valid CSS!

Breadcrumb

© ElectricType
Maintained by My-Hosts.com
Site map | Copyright | Disclaimer
Privacy policy | Acceptable Use Policy
Legal information.