I have the following at the top of my document:
<html class="js" lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
Can someone tell me if I need the xmlns part? I am not 100% sure but I think this is
doing some things to my tags. For example when I look at the tag is see the
following with firebug:
element.style {
height: 100%;
}
If I just have this as at the top of my code then I don't see the element.style ..
<html class="js" lang="en">
Just to give some background. I'm developing an MVC application for use with English. It uses HTML5 things in a few places.
For the current html spec, (which is html5) you will not need any fancy attributes, the following is adequate:
<!DOCTYPE html>
<html>
<head>
<title>Html page</title>
</head>
<body>
<p>This is an example Html page.</p>
</body>
</html>
Also, if you are not using the html5 spec, you should.
If you are using HTML5, then the extra tags probably should not be there as they are not needed any longer.. HTML5 uses a much cleaner syntax. :)
Here is the W3 documentation about this
You do not need to give those attributes in the tag.
<html>
</html>
will work fine even in HTML5 or HTML 4.01
The xmlns attribute may be needed if the document will be processed by XML tools that do not necessarily use HTML namespace as the default. You can see this by saving the document locally and opening it in Firefox; if the xmlns attribute is missing, Firefox will display the document source, just with XML syntax coloring, because it treats all tags just as pure markup with do meaning or default rendering rules.
If the document is served as HTML (Content-Type: text/html), then browsers will imply HTML semantics (HTML namespace).
Regarding the question you asked in the heading, you should put a doctype declaration, such as <!DOCTYPE html>, for all new documents. Otherwise you will trigger Quirks Mode, which means a large and undocumented set of oddities.
Related
I'm wondering if this is a quirk in Dreamweaver:
The first tag in my html5 document is:
<!doctype html>
...and the last tag is:
</html>
When validating the document (W3C) from within Dreamweaver, I get this error:
Tag must be paired, no start tag: [ </html> ]
Could it be that Dreamweaver doesn't recognize the first tag with !doctype?
<!doctype html> is not an opening-tag. It's an SGML doctytpe declaration.
The <html> opening tag goes after it, like so:
<!doctype html>
<html>
<head>
</head>
<body>
</body>
</html>
Backstory: SGML doctype declarations are usually far more complicated, and when HTML was ostensibly an application of SGML (e.g. in HTML4.01) then HTML documents needed full-form SGML DTDs like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
...however, ever since HTML5 was declared as "a living standard" without version numbers, and no-longer either SGML nor XML (rip XHTML) there was no need for a HTML5 DTD anymore, but for compatibility purposes the W3C and WHATWG said that <!doctype html> (without the older SGML PUBLIC/SYSTEM parts, and without a URI to the actual DTD) should be used.
See here for details: Where is the HTML5 Document Type Definition?
This question already has answers here:
What is the functionality of !DOCTYPE?
(5 answers)
Closed 5 years ago.
The <!DOCTYPE html> tag must be present at the beginning of an HTML document. Can I know the reason why? Also, I've noticed that my webpage works all fine even without this tag.
Here is a sample code along with the tag.
<!doctype html>
<html>
<head>
</head>
<body>
Hello, world!
</body>
</html>
Here is the code without the tag.
<html>
<head>
</head>
<body>
Hello, world!
</body>
</html>
Both of the codes return the same result. What is the actual purpose of the tag and what will happen if it is not present in an HTML code?
The <!DOCTYPE> declaration must be the very first thing in your HTML document, before the tag.
The <!DOCTYPE> declaration is not an HTML tag; it is an instruction to the web browser about what version of HTML the page is written in.
In HTML 4.01, the <!DOCTYPE> declaration refers to a DTD, because HTML 4.01 was based on SGML. The DTD specifies the rules for the markup language, so that the browsers render the content correctly.
HTML5 is not based on SGML, and therefore does not require a reference to a DTD.
source
DTD-Document Type Definition.
also take look at previous answers
Firstly, you've to know doctype declaration is not a tag, but an instructor that tells the browser which version of html you are using or you want use.
In HTML 4.01 doctype declaration refers DTD, The DTD define complete rules for the mark up languages because HTML 4.01 based on SGML.
Html 5 or current version of html does not require the doctype declaration because it does not based on SGML.
But its better always to add the Doctype declaration to your html document so that the browser will understand which type html expect to.
Forget about those smart rendering engines of state-of-art browsers. In terms of the W3C standards, which are the "indispensable" (non-removable) tags for a standard HTML document?
Furthermore, is there any difference about it in the HTML5 standard?
Thanks.
According to the validator, this is valid:
<!DOCTYPE html>
<head>
<title>Title</title>
edit: Even smaller:
<!DOCTYPE html>
<title>Title</title>
The elements which every document must have are: <html>, <head>, <title>.
By the HTML 4.01 specification, the only obligatory tags are <title> and </title>. The same goes for the HTML5 drafts. In XHTML, different rules apply, see the spec.
What is the correct way to use start tag when creating with HTML5
IE: HTML 4 Strict is like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
The standard has been simplified because the previous doctypes were too cryptic. The new doctype is simply <!DOCTYPE html> . You may wonder why it is not <!DOCTYPE html5> but it is simply because it is just an update to the standard of HTML and not a new version of anything. As you can see below, all elements can now have a language attribute.
The <html> element is the root element of a document. Every document
must begin with this element, and it must contain both the <head> and
<body> elements.
It is considered good practice to specify the primary language of the
document on this element using the lang attribute.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
<p>
Jamie was here.
</p>
</body>
</html>
More info: https://dev.w3.org/html5/html-author/#doctype-declaration
you just use
<!DOCTYPE html>
<html>
</html>
First of all, html5 doctype is not case sensitive.
Either one of these three will work:
1) <!DOCTYPE html>
2) <!DOCTYPE HTML>
3) <!doctype html>
You can check the validity here.
It's as simple as
<!DOCTYPE html>
According to the WWW Consortium, the organization responsible setting current web standards, no one has answered this correctly.
The current standard for language declaration is
Always use a language attribute on the html tag to declare the default
language of the text in the page. When the page contains content in another
language, add a language attribute to an element surrounding that content.
Use the lang attribute for pages served as HTML, and the xml:lang attribute
for pages served as XML. For XHTML 1.x and HTML5 polyglot documents, use both
together.
W3C HTML Language Tag Page
Here is the answer regarding DOCTYPE declaration
Use the following markup as a template to create a new HTML document using a
proper Doctype declaration. See the list below if you wish to use another DTD.
W3C DOCTYPE Standards
<!DOCTYPE html>
<html>
<head>
<title>An HTML standard template</title>
<meta charset="utf-8" />
</head>
<body>
<p>… Your HTML content here …</p>
</body>
</html>
Hope this helps.
You use...
<!DOCTYPE html>
followed by your HTML tag etc..
You only need this:
<!DOCTYPE html>
<html>
...
There are several points here. This is supported by all browsers, even old ones like IE6/IE7. All browsers actually nee "html" part from doctype declaration to jump into standards mode.
<!-- simplified doctype works for all previous versions of HTML as well -->
<!doctype html>
Learning Resource:
http://diveintohtml5.info/
http://www.html5doctor.com
The start tag <html> is optional in HTML5, as in HTML 4.01. If used, it must be the first tag. It has different optional attributes: the global attributes of HTML5, and the special manifest attribute. The most common useful attribute in the <html> tag is the lang attribute.
(The doctype declaration is something quite different, and not a tag at all.)
The clearest most definitive answer of what the standard says seems to be for HTML 5.3 at:
http://w3c.github.io/html/syntax.html#the-doctype
Note especially the list-items 1 and 3 which specify that the doctype-statement is case-insensitive. Also note the number of spaces inside the statement can vary.
And note the clause "A DOCTYPE is a required preamble."
I'm working with a publishing system that uses custom tags. These are interpreted on the server. The problem is, that they cause big problems with Opera, when viewed locally (custom tags are not interpreted).
Opera is handling these tags differently from other browser. It looks like it is closing the tag at the end of the document (even if the tag contains closing slash). I'm just wondering, if such behavior is considered bug or feature.
Also, if you have any idea how to hack such code so that I can debug HTML+CSS for Opera locally (without interpreted custom tags), please let me know. Thank you.
Try the folowing code to see it in action (live example):
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Non-standard tag behavior in Opera</title>
<style type="text/css" media="all">
div { background: yellow; padding: 1em; }
nonstandardtag { border: 1px solid red; }
</style>
</head>
<body>
<div>
<nonstandardtag>content of non-standard tag</nonstandardtag>
main tag content
</div>
<div>
<nonstandardtag />
main tag content
</div>
</body>
</html>
I use opera for more than 5 years. It is the browser that approaches the standard the best. Most of the sites that look bad in Opera are "optimized" for IE.
But an obvious question is, why do you need to use nonstandard tags? You can use the div and span tags for almost any nonstandard solution.
Short: it's not a bug. Despite the DOCTYPE, your page is not interpreted as XHTML (and this is intentional).
HTML simply doesn't support the self-closing tag syntax the same way as XML.
In HTML, in practice <foo /> is the same as <foo> or <foo /="">. In theory it's same as <foo></foo>>.
You need to tell browser to interpret page as X[HT]ML. DOCTYPE is not enough. To do this locally, file has to have .xml or .xhtml extension. When you serve file over HTTP, you must set Content-Type header to application/xhtml+xml or similar XML type (for static files usually .xhtml file extension does the job).
Your live example is served as text/html, so it won't be interpreted as XHTML, and won't work as you expect.
BTW: XHTML doesn't allow non-standard elements. If you want to add your own elements anyway, you should at least use your own namespace.
This seems to be fixed in Opera 10. So I guess it was not a feature.
One, you don't need non-standard elements. Two, whatever you claim with your doctype, this isn't XHTML but HTML (as you make clear with the <meta http-equiv="Content-Type" content="text/html…. That obviously means that browsers use their HTML parsers, and those don't (and shouldn't) support XML's shorthand syntax <element/> for empty elements.
Short answer: there are no guarentees or requirements on what a User Agent may do if you feed it malformed data.