XHTML tutorial-head and DTD

Source: Internet
Author: User
Why is an error?

In the previous section, we got an error message while verifying our webpage, But we wrote the code according to the XHTML standard throughout the webpage creation process. In fact, the problem lies in the "Header" of the webpage. Next we will solve this problem.

<Head> Part

In the previous tutorial, except for the <title> tag, we modified the content between <body>, that is, the content displayed on the page. What is the

Note: Most of the labels and attributes in this section are hard to remember. In fact, they are automatically generated when we use the web page creation software to create webpages. The purpose of this section is to understand the meaning of these labels and make some manual modifications when necessary. Open our own index.html "and insert the following content in the middle of Code:

 
1. <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>

This code tells the browser that our webpage uses gb2312 Chinese character encoding. The <meta> information without this section is one of the reasons for the problem during the last verification.

 
2. <meta name = "keywords" content = "primary school students, bullied students, homework during the cold and summer vacations, and parents"/>

This code is the keyword of index.html written for the search engine.

Note that the <meta> tag is also an empty tag. Do not forget to add /. <Meta> tags serve far more than these functions. However, it is difficult to understand the actual use of <meta> tags without practical application. If you want to learn more about <meta> tags, you can go to Baidu to search for related knowledge.

<Head> label description

As mentioned earlier, the content of

DTD

If we verify our webpage again, we still get an error message indicating that the DTD file cannot be found, what is the DTD file? To put it simply, anyone (usually a software similar to a browser) wants to read our files and tell them which rule we follow. Take the verification process as an example. If we use the DTD of html4.01, The validators will think that we are using the web page written by the html4.01 rule, then, according to the corresponding rules, a line of code is validated and the verification result is returned.

The webpage we create uses XHTML rules, and of course the xhtml dtd. However, as we mentioned earlier, the xhtml dtd is also divided into a relatively loose transitional DTD and a strict DTD with strict requirements. In this tutorial, we will declare a strict DTD on the webpage. If you want to learn more about the DTD, you need to learn XML. This tutorial will not discuss it too much.

Next we will declare a DTD for our webpage. Open the previously saved "index.html" and enter the following code in the first line (before the <HTML> tag:

 
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>

Add the following attributes to the <HTML> tag:Xmlns = "http://www.w3.org/1999/xhtml". This is called the namespace attribute and belongs to the XML category. We will not discuss it too much here.

The role of this Code is to declare that our web page is using a xhtml1-strict.dtd. Now, submit the page to the validator of W3. This time, a "this page is valid xhtml1.0 strict!" is returned !" . This indicates that there are no errors in our code and it fully complies with the strict (strict) Standard of xhtml1. Of course, this may not always happen in actual work. In the actual web design process, there will always be various reasons for us to write nonstandard code. In this case, the validator will provide an error report. You only need to modify the code as prompted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.