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
Related
Why is <!DOCTYPE html ... > used in html file?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The DOCTYPE Declaration (DTD or Document Type Declaration) does a couple of things:
When performing HTML validation testing on a web page it tells the HTML (HyperText Markup Language) validator which version of (X)HTML standard the web page coding is supposed to comply with. When you validate your web page the HTML validator checks the coding against the applicable standard then reports which portions of the coding do not pass HTML validation (are not compliant).
It tells the browser how to render the page in standards compliant mode.
For more information refer to this "<!DOCTYPE html>" What does it mean?
It tells the browser that the following code is to be treated as a particular version of html code.
The browser knows then to look for an open HTML tag <html> and treats everything like html until it reaches the close HTML tag </html>
<!DOCTYPE html> is all that's needed now.
The term DOCTYPE tells the browser which type of HTML is used on a webpage. Here is link of official page which explains your query why and what is
<!DOCTYPE html>
A doctype defines which version of HTML/XHTML your document uses. You would want to use a doctype so that when you run your code through validators, the validators know which version of HTML/XHTML to check against
The declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.
In HTML 4.01, the declaration refers to a DTD, because HTML 4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
HTML5 is not based on SGML, and therefore does not require a reference to a DTD.
Tip: Always add the declaration to your HTML documents, so that the browser knows what type of document to expect.
The <!DOCTYPE html> declaration is used to inform a website visitor's browser that the document being rendered is an HTML document. While not actually an HTML element itself, every HTML document should being with a DOCTYPE declaration to be compliant with HTML standards.
For HTML5 documents (which nearly all new web documents should be), the DOCTYPE declaration should be:
<!DOCTYPE html>
Show to the browser than the file is a HTML5.
Is followed by the lenguage etiquete according to HTML5 good practiques.
<!doctype html>
<html lang="es">
In this case the second line indicates to the browsers than the file is in example, spanish in this case <html lang="es">
is important for building an HTML documents it is not just HTML but it is an instruction to the web browser about what version of HTML the page is written in.
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>.
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.
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>
Learning a bit about the differences between XHTML and HTML, I looked at the source of one of our pages:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
Is this correct? Seems like it’s trying to be a HTML page, but then has a link to an XHTML namespace?
It looks like somebody was using an XHTML doctype, and the associated xmlns attribute:
<!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">
And then they heard HTML5 was the shiny new doctype, so they changed to that and ended up with:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
Just to make it clear, this is what it should be:
<!DOCTYPE html>
<html>
Your code provided,
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
is perfectly fine. It means that the web page is using XHTML5, an XML serialization of HTML5. If you would like your pages to be rendered as proper XHTML5, though, the content-type header of the page should be sent as application/xhtml+xml; text/html is not allowed in XHTML5.
For practical reasons (especially compatibility with previous IE versions, most notably IE 6), you should use HTML5, not XHTML5, like the following:
<!DOCTYPE html>
<html>
Note, of course, that the xmlns attribute has been removed.