Foreword:
Nowadays, everyone pays attention to standard website building, and the technology used in standard website building is mainly XHTML+CSS. Now we generally use HTML code, so how should I convert it? And what is the difference between HTML and XHTML? In this tutorial, you will learn the differences between HTML and XHTML, and how to convert HTML to XHTML. After all, XHTML is the direction of development, so I think it is necessary to publish this tutorial on this site. I feel that if you want to use standards, it's better to learn HTML first because it's easier, and then look at this tutorial. At the same time, this is also a continuation of the WEB standard XHTML&CSS I have published.
Introduction to XHTML:
In fact, the standard we are talking about should be XML, so why should we learn XHTML? Because the current HTML code is cumbersome and full of risks, but the XML usage environment is not yet mature, an excessive product has been launched, which is XHTML, which plays a role of ups and downs. Some people also think that XHTML is an upgraded version of HTML, which is actually correct. My understanding is that XHTML is a markup language that makes HTML more standardized, making HTML more powerful and reducing the cumbersome code, especially tables.
XHTML was established as a standard by the international standards organization W3C (World Wide web Consortium) on January 26, 2000. It is considered the latest version of HTML and will gradually replace HTML. All browsers now support XHTML, and XHTML is compatible with HTML 4.0. Some people also think that XHTML is HTML4.01. If you write a standard-compliant website during the learning process, you can pass W3C verification. After passing the verification, you will get a mark, usually XHTML1.0 certification and CSS verification. I don’t know how many websites in China have passed these two verifications at the same time. You can go to http://www.w3.org/ to verify your site. If it meets those two rules, we will give us two pieces of code to add to your webpage to show to others. It shows that you adopted the standard to build the website, awesome!
Why we use XHTML
Let’s look at an HTML that contains an error code, as follows:
This is bad HTML
Bad HTML
Although it contains error codes, it can still be displayed normally when we browse it in the browser. XML is a markup language, but it requires that any element that appears in a web page should be marked. XML is used to describe the data in the web page, while HTML is used to display the elements in the web page. The various browser technologies we currently use on the Internet, including laptops, mobile phones, etc., all require that some content to be browsed must be correctly tagged. If there are incorrect tags, the display may be particularly confusing or even unable to display properly.
So combining HTML and XML, as well as other technologies, we get a language that is useful now and will be useful in the future - XHTML. When everything is standardized in the future, we will use XHTML correctly formatted tags so that all browsers can execute it correctly, so it is necessary for us to start learning XHTML now.
The difference between XHTML and HTML:
XHTML is a new technology. Before browsers and other software support it, it should be necessary for us to be familiar with this technology. In order for us to better learn XHTML, we should be familiar with HTML4.0. We can download a reference manual to get familiar with it. In order to make it easier for us to learn XHTML, in other words, when we use HTML to write code now, we should try our best to write as few error codes as possible, such as: use lowercase characters to write HTML, and add the end of the tag after each tag. For example:
Welcome to the web teaching website
There must be an end, and we must maintain this rule.
The biggest difference between them is:
1.XHTML elements must be nested correctly.
In HTML, some elements can be nested incorrectly and still display normally, such as:
This text is bold and italic
But in XHTML it must be correct It can be used normally after nesting, such as:
This text is bold and italic
Note: This error usually occurs in tags when nested multiple levels. Such as:
- Coffee
- Tea
- The correct one should be:
Coffee
Tea-
- Black tea
Milk
- Observing the above two pieces of code, we can see that correctly we insert the
tag after
.
XHTML files must have the correct organizational format.
All XHTML should be correctly nested within elements starting with and ending with . Other elements can have child elements, and child elements should be correctly nested within their parent elements. Inside. For example:
...
...
Tag names must be in lowercase letters. Because XHTML documents are XML applications, XML is case-sensitive. The symbols
and are two different tags. For example, the error code:
This is a paragraph
a paragraph
All XHTML elements must be closed There cannot be empty elements that are not closed in our code. In fact, it is easier for us to end this point. Should there be an end to the beginning? For example, the error code:
This is a paragraph
This is another paragraph
The correct one is:
This is another paragraph
独立したタグを /> で終了する必要もあります。
例: エラー コード
これは休憩です
ここに水平方向の罫線が入ります:
これが画像です
正しいコード:
これは休憩
ここに水平方向のルールがあります:
これが画像です
上記の例を通して、基本的に HTML と XHTML の違いがわかりました。次に、変更を試みる必要があります。小文字のタグを使用したり、タグの後に終了タグ記号「/>」を追加したりするなど、現在の HTML は今後変更されます。
XHTML の構文
簡単に言えば、XHTML を記述するときはきれいな HTML 構文を使用する必要があります。
XHTML のその他の構文要件:
属性名は小文字である必要があります。例:
エラー コード:
正しいコード:
属性値は引用符で囲む必要があります。例:
間違ったコード: