Quest for Minimalistic DTD HTML Language Declaration Standards - html

In a search towards minimalistic webcoding practices I saw this on the top of my webpages:
<!doctype html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="nl" xml:lang="nl">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="nl"/>
A: when should one keep the second line (xmlns) and when can it be removed?
B: my website is multilingual so pages come in variety of languages. I kept the xmlns since I swa you can put in lang= and xml:lang= so thought that might be handy, but I don't use xml I think... just php generated contents etc. UPDATE I just got advise to use <html lang="de"> which will suffice for me. True?
C: when does one need the third line http-equiv? When can it be removed entirely?
D: do browsers recognize/process the fourth line or do they skip it nowadays?
Thanks very much!

If you haven't already, read up on HTML5 here or maybe here, and maybe even here. HTML5 is the latest HTML spec currently under development by the W3C, and is pretty much awesome.
For your questions:
Q1: See this SO question. Basically, you won't need the xmlns or xml:lang attribute.
Q2: Yes, see below.
Q3: You don't need to specify content-type anymore, however you should always specify the encoding (see below). In reality, though, you can use either one, so I would just stick with the short version. See this SO question for more info.
Q4: That's a difficult question to answer because it really depends on the browser / version. However, it's a moot point since the lang attribute should really be moved into the html tag (again, see below).
Below is what I consider the bare minimum a proper web page should include, (sans the comments):
<!DOCTYPE html>
<html lang="en"> <!-- use whatever language code is appropriate here -->
<head>
<meta charset="utf-8"> <!-- utf-8 is universally the best encoding option -->
<title>My Cool Website</title>
</head>
<body>
</body>
</html>

Related

Why is Microsoft Edge detecting the wrong language on my site?

I'm creating an Angular web app in English, but when I visit the site using Edge, it thinks my site is in Italian. I have absolutely no idea what would make it think that, and everything I find on the subject is geared towards Edge users changing their settings or translating pages. The end user shouldn't have to change any of their settings; they should never get a message that the site is in Italian in the first place.
How is Edge detecting language, and how can I configure my site so that it detects English? The only thing I know is having <html lang="en">, and I have that.
Normally you can specify the language via "lang" attribute. Since it doesn't work in this case, I suggest 3 possible workarounds:
Try making your <html> look like this: <html lang="en" dir="ltr" xml:lang="en">
Try adding this <meta> tag: <meta http-equiv="Content-Language" content="en">
If none of the workarounds above solves this issue, you can directly disable the translator prompt via this <meta> tag: <meta name="google" content="notranslate"> PS: Don't worry because users can still use the translation feature manually.

When is an xmlns declaration in HTML5 really necessary [duplicate]

This question already has answers here:
What does "xmlns" in XML mean?
(5 answers)
Closed 7 years ago.
I'm trying out different web page compositors and most of them start out with a basic structure like this when I create a new project:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Web Project</title>
</head>
<body>
<h1>New Web Project Page</h1>
</body>
</html>
I wasn't really able to find an answer as to why there needs to be an xmlns if it's going to be a normal web page. I know I can omit it if I so desire, I've been writing HTML5 documents before and it was working fine without it.
So when is it actually necessary to provide an xmlns in the <html> element and why do compositors think it should be there when I create a new project? Is there any significance providing an xmlns with the <html> tag when doing HTML5 in the first place? Is there any benefit adding it?
On a regular HTML5 page you don't need it. However, if you want XML-serialized HTML5 (i.e. XHTML) then you add the XML namespace. For example the web framework JSF uses XML-serialized HTML, so there would be one reason to use it.
The HTML validator at http://w3.org does not complain when the xmlns attribute is missing in an XHTML document. This is because the namespace "xmlns=http://www.w3.org/1999/xhtml" is default, and will be added to the tag even if you do not include it.
From http://www.w3schools.com/tags/att_html_xmlns.asp

IE=edge and IE=EmulateIE8

see my post here
In that context
What is the meaning of value="IE=edge"?
What is the meaning of value="IE=EmulateIE8" ?
IE=edge simply tells IE to use the last version of the rendering engine.
It's documented here, just like the less useful (in my opinion) IE=EmulateIE8.
IE=edge helps you avoiding some "compatibility" behaviors. It makes IE9 more compatible with other modern engines.
See this related question for example. I always start my HTML files with
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

IE8 standards mode meta tag

A web application we have for an organisation that is officially upgrading its standard browser from IE6 to IE8 (queue celebrations), we've set all our DOCTYPEs to be <!DOCTYPE html> (as well as fixed other html code) and I thought that in IE8 this would cause the page to be rendered in IE8 Standards Mode. However, it is still shown in IE7 Standards mode.
I've added the <meta http-equiv="X-UA-Compatible" content="IE=8"> into the <head> section and it still fails to default to IE8 Standards mode. I'm presuming at this stage that there must be a setting (perhaps Group Policy etc) that is forcing the mode.
After reading a hack on an MSDN forum that if you put the meta tag before the <html> tag, it correctly displays as IE8 Standards mode, and this worked for me. Is there another way to do this? It just looks terrible seeing the meta tag there...
Here's roughly how each page is made up:
<!DOCTYPE html>
<meta http-equiv="X-UA-Compatible" content="IE=8">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Title</title>
</head>
<body>
</body>
</html>
You could set X-UA-Compatible as a HTTP response header, instead of as a meta tag.
This is a much cleaner solution than placing it above the <html> tag.
A confusing useful blog post concerning X-UA-Compatible and its many intricacies:
http://farukat.es/journal/2009/05/245-ie8-and-the-x-ua-compatible-situation
Two possibilities:
The meta tag definitely belongs into the <head> section of the document.
If this is in an Intranet, this may be IE's "Smart default" kicking in. Yes, there is such a thing as smart defaults. See here. Because if you're in an Intranet, IE8 will automatically go into IE7 compatibility mode so as not to break the many corporate apps that rely on IE7. Makes sense, right? Right?

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.