• Register
110,660 points
12 7 5

When choosing a DOCTYPE, you need to clearly determine which of the two standards to choose: HTML or XHTML . And to facilitate your choice, I decided to analyze the difference between HTML and XHTML .

The main difference between HTML and XHTML is that XHTML is based on XML syntax . And, therefore, it is more strict, and it should not allow those liberties that can be allowed in HTML .

And now let's take a look at the XHTML syntax features point by point :

1. Each tag must be closed

Paired tags should be closed in HTML too, but we all know that there are many single tags in HTML (for example, < img >), and we could safely write this way:

<img src = "photo.jpg" >

However, in XHTML all tags must be closed, even single tags, and they are closed as follows:

<img src = "photo.jpg" />

The only difference is the slash before the second angle bracket.

2. All special fonts should be changed with entities

That is, you cannot write like this: " & ", you need to write this symbol only as an entity, that is, " & amp; ". There is no such rule in HTML .

3. All attribute values ​​must be in quotation marks.

We all know that in HTML you can write like this:

<img src = "photo.jpg" width = 15 >

That is, we have the value of the " width " attribute without quotes. In XHTML, this is unacceptable, and there you need to write like this:

<img src = "photo.jpg" width = "15" />

4. All tags and attributes must be written in lowercase.

To be honest, I never understood why people write tags in uppercase. In my opinion, this disfigures the code, and there is a feeling that it was written without pressing " CAPSLOCK ". But if in HTML this is a matter of taste, in XHTML it is a rule: write only in lowercase.

As you can see, the only difference is in the syntax. There are other minor differences as well, but we won't talk about them. In other words, the only benefit of XHTML is that it is easier to parse the document . And also XHTML is very suitable for lovers of "clean" code. There are no more advantages. All browsers render both HTML and XHTML correctly . Moreover, browsers often process XHTML as HTML , so there will definitely not be any serious differences in appearance between HTML and XHTML .

I chose XHTML for myself , because I really like when the code is "clean" and when it is easy to parse into its component parts ( parsing ). Yes, and in general I'm used to the strict syntax of other languages, for example, Java, so I will still write as validly as possible. And what you choose is up to you, and you already know about the differences between HTML and XHTML .

 

110,660 points
12 7 5