Where should a site’s language be set? - html

I was searching at w3schools about the meta tag, but there's nothing about content language.
What is the place where I should set the site’s language?
Edit: it should be compatible with HTML 5.

The document language should be specified using the lang attribute on the highest element to which it applies — which is usually html. e.g.
<html lang="en-gb">
You can use it to indicate changes in language if needed:
<p>She has a certain <span lang="fr">je ne sais quoi</span></p>
You can also specify the language(s) of the target audience with a Content-Language HTTP header.
Content-Language: en, fr
There isn't much point is duplicating that with <meta http-equiv, especially if you have a suitable lang attribute.

http://reference.sitepoint.com/html/core-attributes/xml-lang
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Related

Breaking multiple values in an attribute into multiple lines?

Let me explain by example:
<html lang="en-US" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# article: http://ogp.me/ns/article#">
...
</html>
As you can see, the prefix attribute in the html tag has multiple definitions. How do I break them into multiple lines? (Considering that a line break is equivalent a space when minified back into a single line... it's kinda tough.)
Is this considered normal?
<html lang="en-US" prefix="
og: http://ogp.me/ns#
fb: http://ogp.me/ns/fb#
article: http://ogp.me/ns/article#
">
EDIT: Facebook does it like this: https://developers.facebook.com/docs/payments/product/
<html lang="en-US" prefix=
"og: http://ogp.me/ns#
fb: http://ogp.me/ns/fb#
article: http://ogp.me/ns/article#">
The attribute values are different. Each whitespace character is stored in the DOM. Whether the difference matters depends on the definition of the attribute. Many attributes, such as class, are defined as taking a set of whitespace-separated tokens as value, and for them, the amount and type of whitespace characters between tokens, or before the first token and after the last token, does not matter.
The prefix attribute is not present in HTML specifications or drafts. The relevant specification is RDFa Core 1.1, which defines the prefix attribute as
“a white space separated list of prefix-name IRI pairs” and contains examples like
<html
xmlns="http://www.w3.org/1999/xhtml"
prefix="foaf: http://xmlns.com/foaf/0.1/
dc: http://purl.org/dc/terms/"
>
So for the prefix attribute, formatting as in the question is acceptable. (Whether it is “normal” in a sense other than “conforming” is a matter of opinion.)
I don't think it's all that "normal". In general, like the comments to your question suggest, it's technically possible but you're opening your page up to (unnecessary) potential parsing errors.
Look to the HTML WG's example regarding using newlines in the title attribute as a concrete example of this.
Furthermore, I was unable to find/remember a single case where I'd seen this used on purpose, with the exception of SVG (but that's not technically HTML).
However, if you run this sample through the W3C's validator, it'll pass with no errors or warnings in regards to multi-line attributes:
<!DOCTYPE html>
<html lang="en-US" prefix="
og: http://ogp.me/ns#
fb: http://ogp.me/ns/fb#
article: http://ogp.me/ns/article#
">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Generally, it's better to be safe than sorry. Since I couldn't find any examples to the contrary in this case, I'd venture to say that other developers would agree (Do by all means correct me if I'm wrong).

Which meta tags before title tag in html with doctype 4.01 Transitional?

So my question is about which meta tags are placed before the title tag when set in the head tag in html with doctype 4.01 Transitional.
Here I give an example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Index</title>
<meta name="keywords" content="whatsoever">
<meta name="description" content="ask stackoverflow">
<meta name="author" content="gugol">
<link rel="stylesheet" type="text/css" href="../css/nicestyles.css">
</head>
<body></body>
</html>
I think I should have the charset attribute first so that everything in the html document is read under the character encoding for the HTML document. But have some doubts about the others.
What would be just the right order??
Modern browsers let you specify the character encoding in a meta tag so that it is applied even to elements preceding it. However, such a tag should appear as early as possible according to HTML 4.01, clause 5.2.2 Specifying the character encoding. HTML5 CR clarifies further, in clause 4.2.5.5 Specifying the document's character encoding, that “the element containing the character encoding declaration must be serialized completely within the first 1024 bytes of the document”.
The point here is that unless the encoding has been specified in HTTP headers or by data interpretable as Byte Order Mark at the start of a document, the browser will scan some initial part, such as one kilobyte, of the document, then infer or guess the encoding from it, tentatively parsing it as Ascii data and recognizing a meta tag if there is one.
Other than this, no order restrictions are placed on the content of a head element, and there is no reason to expect that the order of meta elements would matter.
There is no right order. Your title and meta tags can be in any order and the results will be the same.

What is the correct way to declare an HTML5 Doctype.

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."

Doc Type Definition: A Syntax Question

In the top of my webpages it days:
<!doctype html><html xmlns="http://www.w3.org/1999/xhtml"
lang="nl" xml:lang="nl">
Q1:
Which one is more fault-proof/better in your opinion: <!doctype html> or <!doctype html/>
Q2:
I wonder whether there is anything shorter than this, which will define the language:
<html xmlns="http://www.w3.org/1999/xhtml" lang="de" xml:lang="de">
And should that be ending with > of />?
Thanks very much.
Q1: This is very simple: <!doctype html/> is wrong. The doctype is not a self-closing tag, neither in HTML nor in XML. The only valid declaration for HTML5 is therefore <!doctype html>.
Q2: That depends. You don’t actually need to declare the XML namespace if you’re using HTML rather than the XHTML variant (and the xml:lang attribute would also be pointless). In that case, the doctype (see Q1) is entirely sufficient:
<!doctype html>
<html lang="nl">
…
</html>
On the other hand, if you want to use XHTML then you should add the XML namespace (and, yes, the xml:lang attribute). Using XHTML does have advantages, primarily because some editors/evaluators will treat errors stricter and can thus provide better diagnostics for errors.

Html validation error for property attribute

I am using few facebook social plugins and I am using the meta header. When validating the page, the W3C validator is throwing the error -> "Error: there is no attribute "property".
I am using the XHTML Transitional doctype - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Pls Suggest if I have to change the doctype to something else.
Facebook's plugins use Open Graph, which is built on RDFa. It's RDFa that adds the property attribute to elements. Without this addition, plain HTML has no such attribute. (If you ask me, it's a strange design to add a new attribute without namespacing it, and to re-use half of a <meta> tag. But no-one did.)
To validate XHTML-with-RDFa, you'll need the DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
This means you will have to be writing valid XHTML 1.1. More
In order for a document to claim that it is a conforming HTML+RDFa document, it must provide the facilities described as mandatory in this section. The document conformance criteria are listed below, of which only a subset are mandatory:
All document conformance requirements stated as mandatory in the HTML5 specification must be met.
There should be a version attribute on the html element. The value of the version attribute should be HTML+RDFa 1.0 if the document is a non-XML mode document, or XHTML+RDFa 1.0 if the document is a XML mode document.
There may be a link element contained in the head element that contains profile for the the rel attribute and http://www.w3.org/1999/xhtml/vocab for the href attribute.
Example:
<html version="HTML+RDFa 1.1" lang="en">
<head>
<title>Example Document</title>
</head>
<body>
<p>Moved to example.org.</p>
</body>
</html>
As Open Graph suggests, if you're using HTML5, you're better off just using a prefix attribute like this:
<!doctype html>
<html prefix="og: http://ogp.me/ns#">
<head>
<title>HTML5 site</title>
<meta property="og:title" content="The Rock" />
</head>
<body>
</body>
</html>
You can leave the doctype as is and it will validate.
This approach has also been recommended by an Open Graph developer.