Why is the site running in IE quirks mode? - html

I've got a site: http://www.sucramma.dk
When I'm in FF, Chrome, or Safari, the site is displayed as it should, but in IE the site is left aligned, and is running is quirks mode. Why? The doctype is set!

It's a Byte Order Mark, , which is invisible to most text editors. Try using VIM and killing it or somehow find a different text editor and kill everything before <!DOCTYPE html>
You can simply copy <!DOCTYPE HTML> and everything below it into a new file and save over it, meaning you wont be copying the BOM coming before it to resolve this issue; I've ran into it many times.

http://validator.w3.org/check?uri=www.sucramma.dk&charset=%28detect+automatically%29&doctype=Inline&group=0
The validation fails, see the first error:
Error Line 1, Column 1: Non-space characters found without seeing a doctype first. Expected .
The doctype is not sufficient to oblige the browser to standard mode. When an error it is encountered the rendering fall back to quirks mode.
Correct the errors and try again, you should be done

The site doesn't have a DOCTYPE so it will be running in quirks mode because it doesn't know what DTD to use...
EDIT: As pointed out by BoltClock, it does have a DOCTYPE (I'm just not up to scratch on HTML5 yet). My apologies.
Read more here: http://www.w3schools.com/tags/tag_doctype.asp

Try using full doctype declaration (and without a space at the beginning)
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

I had this issue I changed to <!DOCTYPE html> and the it fixed it

Related

What are the valid declarations for html5?

I've seen the following declaration to utilize html5.
<!DOCTYPE html>
However does one really need to specify this? What actually happens when you use just: <!DOCTYPE>. How can I check what doctype is being used and if there is a default being used with a browser?
What actually happens when you use just: <!DOCTYPE>
Using just <!DOCTYPE> instead of <!DOCTYPE html> triggers browsers to go into “quirks mode”:
https://en.wikipedia.org/wiki/Quirks_mode
https://developer.mozilla.org/en-US/docs/Quirks_Mode_and_Standards_Mode
https://hsivonen.fi/doctype/
So yes to stop browsers from going into quirks mode you really do need to use <!DOCTYPE html>.
How can I check what doctype is being used
Browser don’t “use” the doctype for anything other than deciding whether to go into quirks mode.
…if there is a default being used with a browser?
There is no default doctype browsers use. The only default is: If a doc has no doctype at all, then browsers go into quirks mode. The shortest possible doctype to prevent browsers from going into quirks mode is <!DOCTYPE html>. That’s why it was chosen in the HTML spec to be defined as the standard doctype for HTML (including for all future versions of HTML).
If you are using html 5 you should use
<!DOCTYPE html>
fore on doctype tags have a look on this link

Is <!doctype html> required

Do I need to write <!DOCTYPE HTML> at the top of every page? I don't do it at the moment and everything seems to work fine. What is the purpose of it, if we already have <html>?
It is an instruction to the web browser about what version of HTML the page is written in. The <!DOCTYPE html> is standard for HTML 5. Hope this link help you HTML Declaration
Yes, it is. Otherwise browser will default to Quirks Mode:
References:
Why do I need a doctype? (What does it do)
Why do I need a doctype? (What does it do)
It isn't required as such, world won't end and neither will your code if you don't have it. However, it gives the browser information to what HTML version you are using and not having it can create some issues further on, especially if your sites get larger amounts of code and complexity, and thus is recommended to add to your code.

DOCTYPE HTML not start my webpage on the localhost with console IE message

I´m tryng to run my webpage containing basics scripts <?php..?>,<script>...</script>, in LOCALHOST server, using Apache2triad.
It happens that script are running only to find <!DOCTYPE...> or without it in the IE console, the messages are sending like:
HTML1300:Navigation occured.
HTML1527: DOCTYPE expected. Consider adding a valid HTML5 doctype: "<!DOCTYPE html>".
I already try to use declaration, like:
<!DOCTYPE HTML>
<html>
<body>
<?php echo "Ok, running...."; ?>
or simply:
<html>
<body>
But the console error problem persist... Have you got some idea whats is happening with the server?
Thanks.
Your problem is IE compatibility (it has nothing to do with Apache):
How to use Compatibility View in Internet Explorer 9
You can try to add X-UA-Compatible meta tag:
(it also fixes some layout issues that occur in IE10):
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE9" />
A quote from Mozilla's Quirks Mode:
The DOCTYPE shown in the example, , is the simplest
possible, and the one recommended by HTML5. Earlier versions of the
HTML standard recommended other variants, but all existing browsers
today will use full standards mode for this DOCTYPE, even the dated
Internet Explorer 6. There are no valid reasons to use a more
complicated DOCTYPE. If you do use another DOCTYPE, you may risk
choosing one, which triggers almost standards mode or quirks mode.
How do you see which mode is used?
In Internet Explorer, press F12, and look for Document Mode.

Multiple Doctypes in a single HTML Document

If a HTML document has two doctypes, how will the doctypes affect the rendering of the page and which doctype would the browser pick? Is having two (or more) doctypes in a single document valid or confusing?
Example:
<!DOCTYPE html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
</html>
Only a single doctype declaration is permitted. This follows rather directly from the HTML specifications as well the HTML5 drafts, and it can also be checked using a validator.
Thus, there is no specification of what should happen. The natural expectation is that since browsers process the doctype declaration only in “doctype sniffing” when deciding on the browser mode (Quirks Mode vs. Standards Mode), only the first doctype declaration takes effect and the other is ignored.
This can be tested e.g. as follows (using an HTML 3.2 doctype, which triggers Quirks Mode on all doctype-sniffer browsers):
<!DOCTYPE HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<title>Testing duplicate doctype effect</title>
<script>
document.write(document.compatMode);
</script>
</html>
This displays “CSS1Compat” (= Standards Mode), whereas swapping the doctype declarations causes “BackCompat” (= Quirks Mode).
I believe the very first DOCTYPE is used by the browser and it's against the specification to have more than one in a document.
I think (not sure) that the only situation when multiple DOCTYPE-s may be valid is when using IE conditional comments. Browsers other than IE won't see those, of course.
I remember reading a blog entry (can't find it now, so I may be wrong in this) but some (most?) browsers even ignore the DOCTYPE if it's not the first thing they encounter. (This may have been a bug that got fixed since.)
Here's W3School's reference page about DOCTYPE:
http://www.w3schools.com/tags/tag_doctype.asp
If you have multiple DOCTYPE-s in your HTML page then browser will consider first one, browser parse the DOM line by line. Once browser get DOCTYPE then it will stop looking for other doctypes and will jump to search for HTML tag.
In the above question HTML-5 DOCTYPE is mentioned first and then
HTML-4, according to this browser will render things as HTML-5 doctype
It is better to try once in http://www.w3schools.com/ ... Try to use 'code' or 'kbd' or 'dfn' or 'samp' or 'strong' tag by mentioning both doctypes by priority.

No userData behavior when I have <!DOCTYPE html>?

I wanted to use HTML5 localStorage in IE9 but it does not support local file system (or file://)
So I fallback to use userData behavior.
But I couldn't get it to work.
After all the testing, I figured out that if I remove the <!DOCTYPE html> at the beginning of my html, everything works!
Can someone please tell me why?
and if <!DOCTYPE html> is a must for HTML5 file?
HTML5 is not an official standard yet. If you set a doctype to a given standard, but use commands which are not part of that standard, or you use a doctype the the browser does not know, browser might not interpret these commands.
Maybe the W3C-validator http://validator.w3.org/ can help you