Last active
November 17, 2024 02:20
-
-
Save waldyrious/9260278 to your computer and use it in GitHub Desktop.
Minimal XHTML5 document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width" /> | |
<title>Minimal XHTML5 document</title> | |
<link rel="stylesheet" href="mystyle.css" /> | |
<script src="myscript.js"></script> | |
</head> | |
<body> | |
<p> | |
This is a | |
<a href="https://mathiasbynens.be/notes/xhtml5">minimal</a> | |
<a href="https://blog.whatwg.org/xhtml5-in-a-nutshell">XHTML5</a> | |
<a href="https://www.w3.org/TR/html-polyglot/">document</a>. | |
</p> | |
</body> | |
</html> |
To make this stick, either use the .xhtml
extension for the file (which leads the browser to treat it as XHTML), or configure the server to send the content-type header — for example, in PHP:
<?php header('Content-Type: application/xhtml+xml;charset=UTF-8'); ?>
I don't get why the xmlns
attribute in the <html>
element isn't sufficient for browsers. 🤷
For local/CI validation, xmllint
can be used, though it requires specifying a DTD:
▶ xmllint --noout --valid index.xhtml
index.xhtml:2: validity error : Validation failed: no DTD found !
▶ xmllint --noout --dtdvalid "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" index.xhtml
I found that using <meta charset="utf-8" />
as above results in the following output by xmllint:
▶ xmllint --noout --dtdvalid "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" index.xhtml
index.xhtml:4: element meta: validity error : Element meta does not carry attribute content
index.xhtml:4: element meta: validity error : No declaration for attribute charset of element meta
Document index.xhtml does not validate against http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
Using <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
does work, but both forms are spec-compliant so they should be accepted (and indeed the major web browsers do accept them).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Useful links: