I started learning the basics of HTML and I have studied differences between XHTML and HTML. I have noticed XHTML is much stricter. Consider below markup
<?xml version="1.0" encoding="UTF-8"?>
<!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/TR/xhtml1" xml:lang="en" lang="en">
<head>
<title>Every document must have a title</title>
</head>
<body>
<b><p>hey</b></p><br>
</body>
</html>
I have not properly nested the tags and <br> is not properly closed in XHTML but it does not raise any parsing error and when I have saved the file as test.xhtml then it raised parsing error. So how to actually create XHTML files and also how to use XHTML in HTML5? and could anyone explain me that files saved with .xhtml are XHTML files and with .html are treated as HTML files?
Iam using google chrome. I understand the differences but unable to view practically in the browser. Could anyone help me figuring this out.
Most web browsers have XML and HTML parsers. These use different rules.
In general, the rules they follow are:
If the document has one of various XML content-types and the document in in the XHTML name space: Use the XML parser
If the document has a text/html content-type then use the HTML parser
If the document is loaded from a local file and has a .xhtml file extension, then treat it as having the content-type application/xhtml+xml
If the document is loaded from a local file and has a .html file extension, then treat it as having the content-type text/html
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
I can't fix that error :
Unable to Determine Parse Mode!
The validator can process documents either as XML (for document types such as XHTML, SVG, etc.) or SGML (for HTML 4.01 and prior versions). For this document, the information available was not sufficient to determine the parsing mode unambiguously, because:
the MIME Media Type (text/html) can be used for XML or SGML document types
No known Document Type could be detected
No XML declaration (e.g <?xml version="1.0"?>) could be found at the beginning of the document.
No XML namespace (e.g <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">) could be found at the root of the document.
As a default, the validator is falling back to SGML mode.
Now i use this :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
I read some answers say change to this :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
Or this :
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
Also i saved the file as UTF-8 , but it's not detecting the doctype
I don't understand why .
Here link to my site , i use Laravel 4.
http://test.ibids.co.il/?lang=en
I use http://validator.w3.org to check.
Thanks.
You need to declare your doctype at the very top of the page. Looking at your page source, you have links to style sheets and style tags being written before it. These should appear in the head section of the document
My pages are written and declared as XHTML 1.0 Strict. The first lines goes like this:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
Which I belive is correct for a XHTML 1.0 Strict but nevertheless IE11 gives this warning:
HTML1406: Invalid tag start: "<?". Question marks should not start tags. File: default.aspx, Line: 1, Column: 2
Anyone know if this is somthing I should worry about?
The problem is that although you have created a file with an XHTML doctype you have served it using a text/html media type.
So IE11 (and other browsers) treat the file as an HTML file and parse it with their HTML parser. An XML declaration in an HTML file is invalid, and that's what the browser is telling you. If you had served the file with an application/xhtml+xml media type, the browser would have treated the file as XHTML and used its XML parser to parse it. Then the XML declaration would be handled correctly according the XML rules and IE11 would not give you that warning message.
There's no real problem here. The HTML parser will treat the declaration as a bogus comment and just carry on regardless.
For more information you should read Sending XHTML as text/html Considered Harmful and/or HTML 4, HTML 5, XHTML, MIME types - the definitive resource
If you got here because you're working on an old(er) ASP.NET Web Forms app/site... try turning on Compatibility View... that worked for me
Whenever I write a VF Page, I see the "loose.dtd" file being included automatically in the HTML code(Firebug/Developer Console).
DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"
Please suggest an approach to remove this, as it makes my HTML code to conflict with IE.
This is documented in salesforces documentation. The default doctype is loose, if you want a stricter or different doctype you need to specify it using the docType attribute.
Eg
<apex:page controller="Pagecontroller" docType="html-5.0">
More info here: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_page.htm
I like to serve the page as HTML 4.01, because XHTML is not really taken as XHTML in some browsers anyway, but Facebook's OpenGraph meta tags requires:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:og="http://ogp.me/ns#"
xmlns:fb="http://www.facebook.com/2008/fbml">
but since the DOCTYPE of the page is not XHTML, does it matter if the xmlns are there, and should the page be made into DOCTYPE XHTML instead?
(actually, if the page is HTML, the xmlns is kind of confusing, as it is not really XML, but the Facebook page doesn't talk about how to add the meta tags in a page that is HTML 4.01)
For HTML 4.01 Strict:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
For HTML 4.01 Trasitional:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The xmlns stuff you see in the facebook example are XML namespaces and their purpose is to allow the developer to include custom tailored information to HTML documents.
Think of it like folders in a filesystem.
So when facebook declares:
xmlns:fb="http://www.facebook.com/2008/fbml"
They are defining a "folder" in which their custom tags/attributes/properties are stored, so:
<meta property="fb:admins" content="USER_ID"/>
...where the important part is "fb:admins" is the same as having this on your hard drive:
/fb/admins.txt
which contains the USER_ID value.
So it's just a way to keep data organized and separated.
Hope this clears things up for you.
It won't be valid HTML 4.01 if you add xmlns attributes, but it most likely won't affect the rendering.
I wouldn't use HTML 4.01 if I was you. HTML 5 is the new standard, and you should use it.
Those are XML namespace definitions they exist as a way to avoid collisions in XML element names.
Since this is facebook's protocol, they are the ones that define the namespaces.
It has "nothing" to do with how the page is served.