Is <!doctype html> required - html

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.

Related

what if i use html 5 for one webpage when total project created in html4?

I built my website in html4 and would like to add new tab(which is a link opens in new window). Would like to include videos in it and want to make this page in html5. can i make like this? What are the constraints?
Sorry for bad english and need help.
yes, since you want it opened on a new window, then it should be on a new page.
the constraints are that your html5 page should have this at the top:
<!DOCTYPE html>
and your html4 page should have something like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
More info on the declarations here
There won't be any constraints. The client-side browser is what will handle all of it, and HTML5 is just the term used to refer to features that modern browsers support. The only thing you might want to consider is writing it in a way where it will be backwards compatible with older clients since the rest of your site was written to support HTML4.
It is easy. Change the top line of your html file into
<!DOCTYPE html>
And then you can add html5 tags in your html page.
Yes, you can use html5 for only one page. You need to change only html declaration on
<!DOCTYPE html>
You should remember that doctype declaration must be the very first thing on your page and you can't override it
There are no constraints..In fact you could change all your pages to HTML5 and your HTML 4 code will still work the same as before. No need to change anything as html 5 is fully backward compatible,i.e. html 4 elements work fine in it.

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

Doctype breaking the document (Html5/Css3)

I am building a webpage, and I found a problem which I cannot solve. If I declare the DOCTYPE, the page breaks completely, and if I don't declare it, the IE version won't work properly (the drop down menus won't drop). But, despite of it's broken, if I declare the DOCTYPE, the dropdown menus work at every explorer, including IE. So I really don't know what to do, any idea? I'm currently declaring the DOCTYPE as: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> but I've tried other options and they don't work neither.
Last time I posted here the free server blocked the page (probably too many users, as I'm the only one getting in currently), but these are 2 examples of the page:
with DOCTYPE: http://newfutureuniversity.org/project/
without DOCTYPE (dropdown menus not working with IE9):
http://newfutureuniversity.org/learn/
Any help would be appreciated. Even if it's just to orientate me about where to start searching, as I could't find anything similar.
Using or not using the doctype for modern web pages is no longer optional and is required. It is the very first thing that goes down on a page and never changes. If you created a page without one to begin with, then your whole page is set in quirks mode. Trying to fix it or change it by adding/removing the doctype is, essentially, changing the rules and the target as you go along.
Trying to use jQuery to fix this now is just sinking you into a deeper hole. Add the doctype, use a modern browser to get everything how you want it (IE is not a modern browser), then work on getting IE to follow along.
The charset you should be using is <meta charset="utf-8">
for HTML5 it is nice and small, you have an XHTML declaration
it can simply be:
<!DOCTYPE html>
for HTML 5
Using XHTML tells the parser to be much more strict in what it accepts. you have no <html> root in your document (HTML5 won't care about this).
content type specification is different in HTML5 as well
instead of <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> you can use <meta charset="iso-8859-1" /> if that is your desired character set.

Why is the site running in IE quirks mode?

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

Adding doctype url causes eternal refreshing

I have a page that had the doctype:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
I need to add the URL to the end, or jQuery's datepicker does not display correctly. When I make the doctype say:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
The page begins to refresh it self over and over. I can't put up the code here because of NDA, but I am hoping that someone may know what would cause this to happen.
UPDATE: It looks like this doctype has problems with EasyListBox, which seems to be my problem.
The Doctype declaration shouldn't be causing the infinite refresh. It is most likely a bug in your code.
The doctype has nothing to do with that so it must be elsewhere.
Try to pare down the page so that it still replicates the error, but no longer exposes anything that might be under NDA. If you still haven't found the bug by this process of elimination, then you'll be able to post the page for us to see :)
Just try the simplest doctype ever,
<!doctype html>
the html5 doctype. It should work fine with the JQ date picker and pretty much everything else.
Doc-type and Jquery datepicker don't have a direct relationship, your problem for the refreshing loop on your page is without any doubt on your code...
Post your code or provide some link to it to allow us to help you correctly!
Ps: Doc-type does influence the way your browser reads and interpreters your page...