HTML은 HTML 문법 또는 XHTML이라는 XML 문법으로 브라우저를 통해 네트워크를 여행할 수 있다.
HTML5 과 HTML/XHTML
HTML5 표준은 위의 두가지의 문법을 모두 정의한다. MIME 타입(HTTP 헤더 content-type 으로 전송되는)이 어 떤 문법을 사용할지 결정한다. XHTML MIME 타입은 "application/xhtml+xml"이며 그 이외는 "text/html"을 사용한다.
아래의 예제는 HTML 문서와 XHTML문서 각각의 HTTP 헤더를 보여준다.
HTML document
HTTP/1.1 200 OK Content-Type: text/html <!DOCTYPE html> <html lang=en> <head> <meta charset=utf-8> <title>HTML</title> </head> <body> <p>I am a HTML document</p> </body> </html>
XHTML document
HTTP/1.1 200 OK
Content-Type: application/xhtml+xml
<html xml:lang="en" xmlns="https://www.w3.org/1999/xhtml
">
<head>
<title>XHTML</title>
</head>
<body>
<p>I am a XHTML document</p>
</body>
</html>
MIME type vs DOCTYPE
HTML5 이전에는 HTML 4.01 과 XHTML 1.0 두개의 표준이 분리되어 정의되었다. XHTML1 표준에 따르면, XHTML을 사용하기 위해서는 특별한 DOCTYPE을 정의해야 한다고 명시되어있다. 하지만 모든 브라우저들은 이 표준을 구현하지 않았고 반대로 HTML5 표준에서 다음과 같이 결정되었다. "페이지에서 content-type을 text/html로 전송한다면 XHTML을 사용하지 않는 것이다."
Instead, the proper MIME type must be present in the Content-Type
HTTP header. If you only put the MIME type into an HTML meta tag like <meta http-equiv=…>
, it will be ignored and treated like text/html
.
If you serve your pages as text/html
and believe that you are writing XHTML, you may face several problems, as described in these articles:
- No to XHTML an excellent article from Spartanicus
- Beware of XHTML by David Hammond
- Sending XHTML as text/html Considered Harmful by Ian Hickson
- XHTML's Dirty Little Secret by Mark Pilgrim
- XHTML - What's the Point? by Henri Sivonen
- XHTML is not for Beginners by Lachlan Hunt
Support
Most browsers currently support XHTML, including Firefox, Chrome, Safari, Opera, and Internet Explorer (since IE 9). (Internet Explorer 8 and older browsers instead show a download dialog box for unknown file types when they see an XHTML document with the correct XHTML MIME type.)
Also be aware that many popular {{Glossary("JavaScript")}} libraries and developer tools have limited or no support for XHTML.
Differences from HTML
See Properly Using CSS and JavaScript in XHTML Documents for a partial list of differences between HTML and XHTML.