HTML: How to initiate HTML document header - html

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

Related

Auto created teext when opening new html-page in Expression web

I'm learning to use Expression Web 4.0
When opening a new html-page, the following text is automatically created:
<!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">
Is this code redundant, is this needed (or demanded by owners), or what?
Bent
The doctype is used to tell the web browser the particular version of html used to create the web page. It's also responsible for triggering a particular browser rendering mode. It is standardized by World Wide Web Consortium (W3C)
check the list of DTD

How can I tell if the following Web page source code is XHTML, HTML or XML?

I am working with this Web Page for improving my programming skills:
http://www.studenti.ict.uniba.it/esse3/ListaAppelliOfferta.do
If you take a look at its source code, you can see HTML peculiar tags like
<head> <body> <title>
The question is: I am quite sure this page is not in XML, so is it simple HTML or XHTML?
According to my knowledge those two are quite similar.
How can I tell which of the two it is? If I must choose I'd say simple HTML (5 or 4) but I am not 100% sure!
Look for a Doctype declaration at the very beginning of the document.
If it is XHTML, the doctype will look like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
If it is HTML5, it will look like this:
<!DOCTYPE html>
See the W3 Spec for information on Doctype. More information here at the Mozilla Developer Network, too.
The Website you linked has <!DOCTYPE html> declared, which instructs the browser to interpret the document as HTML5 markup.
The <!DOCTYPE html> declaration indicates that it is HTML5. Of course, it might not actually be HMTL5, but it's claiming that it is. The only way to be sure is to run it through an HTML5 validator.

Declaring XHTML doctype then using HTML content-type

I noticed a very popular forum I use, which ironically is one of the biggest web-development forums in the world, uses this:
<!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" xmlns:fb="http://www.facebook.com/2008/fbml" dir="ltr" lang="en" id="vbulletin_html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
...
I know it's a transitional doctype, but if you're going to tell the browser to render the markup as HTML, what on earth was the point in using XHTML? I can't help but think of the wasted time using all those needless closing tags.
This is still more common than people would like, but why is this so? Surely it defeats the whole purpose of using XHTML?
The main practical benefit is that it allows you to use XML in your tool chain up to the point where it is delivered to the browser. Most users don't benefit from this beyond having simple syntax highlighting algorithms in their editors, but it does allow the use of XSLT and other XML tools.
Some people consider XHTML to be stricter (and therefore better) then HTML (although the DTDs for XML are less powerful then SGML so while it removes some exceptions on requirements for tags and attribute quotes, HTML allows a validator to spot problems such as <a><b><a></a></b></a>.
Some people just like explicitly closing all their tags.
Some people were introduced to web authoring with XHTML (it was the flavour of the month for more than a few years) and never gave serious consideration to the alternatives.

Why and how to use <!DOCTYPE>? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
What's up, Doctype?
HTML: What is the functionality of !DOCTYPE
Okay, when I first learn HTML, I basically learn from trial and error as I went along, and didn't really sit down to properly learn it as far as I can remember. As a result of this, I've missed out a lot, and therefore, I've decided to start from the basics for my own benefit. :) So here I am, (re-)learning HTML.
Now, my question - the <!DOCTYPE> tag confuses me more than any other HTML tag I've ever come across, so I've come here to clear up any questions I have regarding it so I can use it confidently. :)
Firstly, can someone explain to me why it's necessary to use a <!DOCTYPE> tag in your webpages? They work fine without them, don't they? I've read that it is so it can be validated against the standards of the W3C, but that's all I know. A little more detail would be appreciated. :)
Secondly, after reading up on it, I'm still confused as to what exactly goes in my <!DOCTYPE> and how to type it out. For example, this is one kind of DOCTYPE I've seen used:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Yet I've also seen other variations, and from what I've read, there are different DOCTYPES to validate against - it's all so very confusing, which should I use in my webpages if I was going to use one?
W3C has a pretty good answer to this at http://www.w3.org/QA/Tips/Doctype
Why?
Why specify a doctype? Because it defines which version of (X)HTML
your document is actually using, and this is a critical piece of
information needed by some tools processing the document.
For example, specifying the doctype of your document allows you to use
tools such as the Markup Validator to check the syntax of your
(X)HTML. Such tools won't be able to work if they do not know what
kind of document you are using.
But the most important thing is that with most families of browsers, a
doctype declaration will make a lot of guessing unnecessary, and will
thus trigger a "standard" rendering mode.
Basically if you leave it out, the browser will try and guess what rendering mode to use, and it might cause some unexpected results.
it basically tells the browser how to interpret the page you're sending it. If you don't send anything, it has to make guesses. Some constructs are valid in a format while invalid in others, etc. Some browsers may display your page correctly while others don't. So yes, do choose and send a DOCTYPE.
There are several doctypes you can use, xhtml, html strict, html transitional, 4.01, etc. You can see a list of valid types here ... http://www.w3.org/QA/2002/04/valid-dtd-list.html
The declaration refers to a Document Type Definition (DTD). A DTD specifies the rules for the markup language, so that the browsers render the content correctly.
Going forward, for html5 compliance, the correct tag is simply:
<!DOCTYPE html>
You set a doctype to say to your browser or somthing else what you going tho do. Its look like what you do whit a business card
There are several doctype's. The most yoused doctype's are transitional:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-transitional.dtd">
The some stricter doctype is: (see "strict")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Also you can youse a speciffie doctype declaraition for youse a frameset. But this is outdated, frameset is a unnecessary for my but i will show you the doctype for this. But forgot the framesets this is an not useful html element whit html5. Here see you the follow frameset doctype:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
And at last. You can youse a language attribuut for your the doctypes. This can youse by html and xhtml.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Is it ok to remove the lines below in a HTML file?

Is it ok not to include such lines in a HTML file? Removing these lines makes the code look more clean.
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
When I use dreamweaver to create a HTML file, these lines are automatically included.
No, you should NOT remove those lines.
You can, however, switch the <!doctype>-declaration to the one of HTML5, since that will still trigger standards mode in all current browsers, even though they don't yet implement HTML 5. It looks like the following:
<!DOCTYPE html>
Which is a bit more clean than the ordinary one you use looks like. You can also read a little more about the new doctype-declaration here. You can also learn more about what will change in HTML5 here.
No that is not allowed. It sets the character encoding, i.e. how the browser should read it.
But the new HTML5 elements make the whole thing look easier and cleaner. So:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
becomes --> <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
lang="en"
xml:lang="en">
becomes --> <html lang="en">
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
becomes --> <meta charset="UTF-8">
<link rel="stylesheet" href="style.css" type="text/css">
becomes --> <link rel="stylesheet" href="style.css">
So the whole code in the <head> becomes:
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
No, you shouldn't remove these lines. The first two lines tell the browser what type of document your page is, and helps the browser render it properly.
The third line tells the browser what character set you're using, in this case so that it knows to render non-latin characters properly.
Those declares the DOCTYPE, which shouldn't be forgotten to add.
Why?
Why specify a doctype? Because it
defines which version of (X)HTML your
document is actually using, and this
is a critical piece of information
needed by browsers or other tools
processing the document.
For example, specifying the doctype of
your document allows you to use tools
such as the Markup Validator to check
the syntax of your (X)HTML (and hence
discovers errors that may affect the
way your page is rendered by various
browsers). Such tools won't be able to
work if they do not know what kind of
document you are using.
But the most important thing is that
with most families of browsers, a
doctype declaration will make a lot of
guessing unnecessary, and will thus
trigger a "standard" parsing mode,
where the understanding (and, as a
result, the display) of the document
is not only faster, it is also
consistent and free of any bad
surprise that documents without
doctype will create.
You can remove the DOCTYPE, html tags and meta tags and still have valid HTML, and if you are happy for your page to take browser default styling they can be safely omitted. The content type and charset can be specified by the HTTP headers if you prefer. As others have already pointed out, the DOCTYPE will affect how styling instructions are interpreted, and also how HTML parsers interpret some invalid markup, so you will need to allow for this.