How to include multiple XML namespaces in HTML5 - html

I'm trying to include Facebook's OpenGraph new meta tags but when I add the required namespaces that would have worked in XHTML, HTML5 won't validate.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml" dir="ltr" lang="en-US">
Where is the proper place to put these namespaces with HTML5?

There are no namespaces in HTML5 AFAIK:
http://mortalpowers.com/news/no-namespaces-in-html5

There is no proper place in HTML5 for the xmlns:og or xmlns:fb attributes.
(One might argue that there is in HTML5 plus some other spec that modifies the requirements of HTML5. But not in HTML5 proper. Validator.nu and the W3C HTML5 validator don't support the kind of "HTML5 plus some other spec that modifies the requirements of HTML5" configuration that would make the xmlns:og or xmlns:fb attributes validate.)

Use XHTML5 to validate it:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml" xml:lang="en">
<!--...-->
</html>

Related

HTML: How to initiate HTML document header

I am still pretty new to HTML and programming in general so this is more of a curiosity question but I am asking as I want to use it the right way.
Whenever I have to initiate an HTML document I start it as below and never observed any issues.
However, when I work in Adobe Dreamweaver and create a new document there it always shows me the below initiation.
Of course I can overwrite this but I would like to know what is the difference and when it would make sense to use any of Adobe's suggested attributes or to add something else to my first four lines.
Can someone help me with this ?
My current initiation:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!-- ... -->
HTML initiation shown in Dreamweaver:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- ... -->
Many thanks in advance,
Mike
<!DOCTYPE html>
This is HTML 5. The current standard.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
This is XHTML 1.0 Transitional. A standard from 2000 designed to combine the transition from HTML 3.2 (1997) to HTML 4 (1998) and XML (which never saw wide use, except while pretending to be HTML 4.
can you explain the single attributes that are different to mine and when it would make sense to use any of them ? Esp. regarding
"PUBLIC",
That isn't an attribute. The PUBLIC portion of a Doctype declaration tells the client where it can download the DTD. (As opposed to the SYSTEM portion which gives it an identifier that it can use to look it up from a local catalogue).
Browsers have never cared about DTDs.
"xmlns",
XML Namespace. It lets you distinguish between elements and attributes that have the same name but are from different specifications.
"http-equiv"
"This is equivalent to an HTTP header with this name"
It is largely a joke. Nothing really implements this except for the character encoding portion of the content-type header and HTML 5 gives much nicer syntax for specifying that.
"content".
The value of the above.
Your first declaration is a HTML5 declaration which is the current standard.
The declaration produces by Dreamweaver is a deprecated XHTML 1.0 Transitional declaration (maybe your Dreamweaver is not up-to-date ?).
See here for more information on doctype

HTML5 Doctype with strict

I want a strict but fully compatible html5 alternative to:
<!doctype html>
Basically I want to ensure the use of closing tags just to keep everything well readable, consistent and highlighted clearly in editors.
The answer to this question is to HTML 5, as XHTML-1.0-strict is to HTML 4.
Thanks in advance.
There is no doctype for "strict" XHTML5 validation. For XHTML5 the doctype is even optional, as the doctype is only for stopping the browser to switch to quirksmode. There is no such quirksmode for XHTML. It is recommended to use the HTML5 doctype (with capitalised DOCTYPE) if you are planning to use it as a polyglot document. In that case you would use the doctype:
<!DOCTYPE html>
However, if you want to validate as if the document is using XHTML style syntax, you can achieve that using the advanced options of the validator.
Go to http://validator.nu
Switch to "text field" in the select box (or point it to your online document but make sure it is served as XHTML not text/html
If using the text field paste in your document. In my case I used the following:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta charset="UTF-8" />
</head>
<body>
<p>test
</body>
</html>
Select XHTML5 + SVG 1.1 + MathML 3.0 from the Preset field. This will pre fill the scheme as http://s.validator.nu/xhtml5.rnc http://s.validator.nu/html5/assertions.sch http://c.validator.nu/all/
Click Validate
Using my document it will warn about the missing close </p>.

Does HTML 5 need `<html xmlns="http://www.w3.org/1999/xhtml">`

When writing a html 5 doctype, are you supposed to include the <html xmlns="http://www.w3.org/1999/xhtml"> as you did when previously using HTML4 doctype or should a different xhtml be used?
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
HTML5 does not require the use of the xmlns attribute as that is specific to XHTML (which means not even HTML 4 uses it either).
If you're just serving regular HTML5, then you can leave out that attribute entirely:
<!DOCTYPE html>
<html>
The xmlns attribute is only required if you're writing and serving XML-serialized HTML5, aka XHTML5.
No, you don't need to include it. This should be enough.
<!doctype html>
<html>
No you don't. In fact, if you include it, then it isn't HTML5, it's xhtml.
The xmlns part is an XML namespace reference. HTML5 is not XML.
In fact, if you were using that xmlns previously, then you weren't using HTML4 either, you were using xhtml. They're not the same.

html5 doctype attributes

I have updated my sites doctype from XHTML to HTML5,
I currently have:
<!DOCTYPE html>
<html lang="en-GB" xml:lang="en-GB" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
my question is, are the attributes xml:lang and xmlns still required as I have migrated from xml to html, i'm thinking not but would like to know if there area any situations in which they should be maintained?
Thanks in advance
Have a look at the global attributes.
You should only use the xml attributes if you have aa xml document (http://www.w3.org/TR/html5/global-attributes.html#the-lang-and-xml:lang-attributes)

HTML Document type and XML namespace

I understand that in order to instruct the browser how to handle HTML page I need to specify a DOCTYPE... For a page that i built with HTML5 I used the following:
<!DOCTYPE html>
When i am viewing other sites that are using the same DOCTYPE, there is an additional definition inside the <html> tag, such as:
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
What does the xml namespace do that it is needed inside the HTML tag in addition to the DOCTYPE definition?
Thanks!
Joel
If the xmlns attribute is set, it's a XHTML (XHTML5) document.
This indicates a HTML5 document:
HTTP-Header Content-Type: text/html
<!DOCTYPE html>
<html>
And this indicates a XHTML5 document:
HTTP-Header Content-Type: application/xhtml+xml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
If the webpage is using XHTML5 an does not have the xmlns attribute, it wont be displayed properly (Firefox would display the XML-DOM instead of the page).
HTML5 isn't XML, so the informations in the html tag aren't needed