This article explains how to define an XHTML document.
Defining document Declaration types
At the top of the page, you need to create a declaration document.
Without the specified document, your HTML is not only incorrect HTML, but most browsers use ' quirks mode ' to interpret them, meaning that the browser will not understand your ideas and will use their own methods to parse the code. Your HTML code has no flaws, CSS is perfect, but there is no declarative documentation, or the wrong statement document, your Web page looks like a short-sighted in a patchwork, learning to have difficult gibbon babies.
XHTML 1.0 Strict declares documents:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Here's the XHTML 1.1, the next best version of XHTML, but there's still a problem.
"-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
If you've just come over from HTML 4, or Netscape 4 advocates, you can use XHTML 1.0 Transitional.
"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The only reason to use it is to adapt to the old few browsers, Transitional XHTML 1.0 allows the old HTML 4 performance elements, which can be better performance in Netscape 4 old browsers, but using these elements will create less web usability.
Finally, if you have a quirk of using Fram, use the XHTML 1.0 Frameset to declare the document.
"-//W3C//DTD XHTML 1.0 Frameset//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
Note that the DOCTYPE
tag is a bit rebellious and needs to be marked in front of the exclamation mark, and that breaking rule is the only one that does not close the tag.
Language Declarations Language Statement
You should html
xml:lang
determine the language of the document through the HTTP header or the properties in the start tag. Although this is not necessary for the correct XHTML document, it is for usability reasons. The value is abbreviated, for example, ' En ' stands for English, ' FR ' stands for French waiting.
Example:
xml:lang="en">
After declaring the main language, if the content is in another language, it can be used xml:lang
for example <span xml:lang="de">HTML Hund</span>
.
Content types
The media type and character settings for HTML documents also need to be specified, such as using the HTTP header:
Content-Type: text/html; charset=UTF-8
The previous section (here text/html
) is the MIME typeof the file, which lets the browser know the media type and function of the file. All files have many types of MIME type, a JPEG image is, image/jpeg
a CSS is text/css
, HTML is text/html
.
The latter part is the character setting.
Using the ' http-equivalent ' meta tag is the easiest way to build an HTTP header, as follows:
http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Some are complicated, but more advantageous (since this is a correct HTTP header and compressed HTML), this is done to the server-side language PHP:
header("Content-Type: text/html; charset= UTF-8"); ?>
If you want to use server-side language, you can use the '. htaccess ' file directly in the server settings. Most servers (Apache compatible) can use a file named '. htaccess ' in the root directory to define all the '. html ' file MIME type and character settings.
AddType text/html;charset=UTF-8 html
The West often sets characters to ' Iso-8859-1 ', based on the Latin language, the Japanese language is ' shift_jis ', ' UTF-8 ' is a version of the Unicode Transformation format that provides a wider range of uses for unique characters in most languages. Basically, you need to set the character to let the user know. In addition to the fact that you are using a Latin based language (including English), where iso-8859-1 can be used everywhere, you should use UTF-8 because it shows most of the characters in most languages and is very safe because it works on most users ' computers.
You can learn more about the elsewhere on the web.
XHTML should use application/xhtml+xml
MIME type. This is an XML program. Unfortunately, most browsers do not have a clue to it. So usually used text/html
. It can be used according to W3c,xhtml 1.0 text/html
, but XHTML 1.1 is not. But you can set the MIME type on the server side.
Htmldog uses PHP to set XHTML 1.1 to use the application/xhtml+xml
MIME type service to understand this browser, such as Mozilla, to set XHTML 1.O Strict for other browsers such as IE text/html
. The procedure is as follows:
<?if(stristr(\$_SERVER["HTTP_ACCEPT"],"application/xhtml+xml")){header("Content-Type: application/xhtml+xml; charset=UTF-8");echo('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">');} else {header("Content-Type: text/html; charset=UTF-8");echo ('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">');}?>
Check to see if the browser accepts application/xhtml+xml
MIME type, and if so, the MIME type takes XHTML 1.1, if not the text/html.
In addition to reassuring you know that you are doing the right thing and preparing for the right things for yourself in the future, the direct benefit of using this method is that Mozilla will view your file as an XML program, if your XHTML file does not submit to IE completely does not work, not well formed. You can debug with a checksum without having to run the document.