What are the differences between html and xhtml?

青灯夜游
Release: 2023-01-03 09:31:39
Original
10217 people have browsed it

Difference: XHTML elements must be nested correctly, and the nesting order of tags must be correct. XHTML elements must be closed, that is, there must be a closing "" tag; while some elements in HTML can omit the closing tag. XHTML tag names must use lowercase letters; HTML tag names can be uppercase or lowercase.

What are the differences between html and xhtml?

The operating environment of this tutorial: Windows 7 system, HTML5 version, Dell G3 computer.

XHTML: Extensible HyperText Markup Language XHTML (eXtensible HyperText Markup Language) is a standard that redefines HyperText Markup Language HTML (HyperText Markup Language) as an XML application.

HTML Document Specification:

HTTP/1.1 200 OK
Content-Type: text/html
 
<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8>
    <title>HTML</title>
  </head>
  <body>
    <p>I am a HTML document</p>
  </body>
</html>
Copy after login

XHTML Document Specification:

HTTP/1.1 200 OK
Content-Type: application/xhtml+xml
 
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>XHTML</title>
  </head>
  <body>
    <p>I am a XHTML document</p>
  </body>
</html>
Copy after login

XHTML Compatibility

Most browsers currently support XHTML, including Firefox, Chrome, Safari, Opera and IE browser (IE 9). (Internet Explorer 8 and older browsers will display a download dialog for an unknown file type when seeing an XHTML document with a properly configured XHTML MIME type). In addition, many popular JavaScript libraries and development tools do not support XHTML.

The difference between HTML and XHTML:

Although XHTML and HTML is almost the same, but it is more important to create the code correctly because XHTML is more strict than HTML in terms of syntax and case sensitivity. XHTML documents are well-formed and parsed using standard XML parsers, unlike HTML which requires a loose HTML-specific parser.

  • XHTML elements must be nested correctly. Generally, html web pages can be "<b><i>main content</b></i>". This is not strict and is wrong in XHTML; the correct one is in the xhtml standard. This must be required "<b><i>main content</i></b>".

  • The XHTML element must be closed. For example, in an example in HEAD, "<meta name="keywords" content="Keywords" >" This tag is feasible in HTML, but for the sake of xhtml standards, it must be closed such as " <meta name="keywords" content="Keywords" />
  • Tag names must use lowercase letters. In previous web pages, many tags were usually arranged in uppercase or lowercase, but for the sake of WEB standards, tags now require uniform lowercase
  • XHTML documents must have root elements. This means that as soon as the tag starts, it must end with the tag. For example, if <body> starts, it must be closed with </body> at the end of the content.
  • Alt attributes need to be added to images. In the past, many times when images were displayed on web pages, the alt attribute could be added or not in the img tag, but now xhtml requires that the alt attribute must be added, otherwise the xhtml verification will prompt an error, even if the alt value is empty. Adding alt can provide a text description for the image, allowing search engines to identify the content of the image, which is a good place to optimize web pages.

Recommended tutorial: "html video tutorial"

The above is the detailed content of What are the differences between html and xhtml?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template