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.
Related
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
Are there any disadvantages if i replace doctype
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
to
<!DOCTYPE HTML>.
<!DOCTYPE HTML> is a HTML 5 doctype declaration,
while <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> is an HTML 4.01 Transitional declaration.
This DTD contains all HTML elements and attributes, INCLUDING presentational and deprecated elements (like font). Framesets are not allowed.
So if you are using any deprecated elements from HTML 4.01, they won't work anymore when you switch to <!DOCTYPE HTML>. But if you're just keeping yourself to HTML 5 standards, you're fine. Normally you won't have this issue.
According to WHATWG <!DOCTYPE html> is recommended because it triggers standard mode in all browsers, including legacy ones. The other doctype you mentioned has simply no use anymore.
A "Document Type Declaration" is an SGML concept for signalling the mark-up syntax and vocabulary for the mark-up that follows. <!DOCTYPE html> does not conform to the requirements of that.
This is unlike <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> which is a SGML conforming Document Type Declaration.
Difference in rendering different doctypes will help you in understanding the difference in depth.
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)
My site looks fine in firefox but in internet explorer everything seems to be bigger so the sizing on the page looks wrong. I really have no idea how to fix this. Any suggestions? Thanks
Start with your code errors [Invalid] Markup Validation of thezenapproach.com - W3C Markup Validator. (scroll down in the validation report to see line numbers and source code.) You can ignore the "unencoded ampersand" errors.
And try a transitional doc type rather than strict:
<!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>
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