Breaking multiple values in an attribute into multiple lines? - html

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

Related

Does HTML5 requires spaces between attributes that are of quoted values?

HTML does normally allow to have no spaces between attributes when attributes have values and those values are quoted.
Example (Reference/Source):
In HTML-documents no White Spaces between Attributes are needed.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>no attribute space</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p class="CLASS"title='TITLE'></p>
</body>
</html>
See the third-last line:
<p class="CLASS"title='TITLE'></p>
^^
Now using such HTML chunk changing the doctype to HTML 5 (<!DOCTYPE HTML>), makes the experimental W3C HTML 5 conformance checker give an error exactly there telling me:
Validation Output: 1 Error
Error Line 9, Column 22: No space between attributes.
<p class="CLASS"title='TITLE'></p>
^
So I thought that HTML 5 is backwards compatible to how browsers deal with HTML in reality and browsers AFAIK deal with this well. So I'm a bit puzzeled at least. I also have problems to decipher the (somewhat needlessly) compilcated HTML 5 specs to be precise at this point because what I did find (W3C again, see http://www.w3.org/TR/html-markup/syntax.html#syntax-attributes) it's not saying that this is (may nor must) be an error.
You are reading a discontinued, non-normative reference. If you look at the definition of the start tag in the specification (which is normative) it says:
Then, the start tag may have a number of attributes, the syntax for which is described below. Attributes must be separated from each other by one or more space characters.
So I thought that HTML 5 is backwards compatible to how browsers deal with HTML in reality and browsers AFAIK deal with this well.
Being compatible with real world markup is a design goal, but lots of things have been obsoleted and leaving out the space between attributes is something that almost never occurs intentionally.
Section 4.3, "Elements" of the document you link in the question says:
Optionally, one or more attributes, each of which must be preceded by
one or more space characters.
Usin the W3C Official HTML Validator, having no spaces between attributes are checked as errors if you use the HTML5 Doctype:
<!DOCTYPE html>
The output message is the following:
Line 9, Column 23: No space between attributes.

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

What's a valid HTML5 document?

I've just been reading the HTML5 author spec.
It states that the <html>, <head> and <body> tags are optional.
Does that mean that you can leave them out completely and still have a valid HTML5 document?
If I'm interpreting this correctly, it means this should be completely valid:
<!DOCTYPE html>
<p>Hello!</p>
Is this correct?
You can check out the spec here:
http://dev.w3.org/html5/spec-author-view/syntax.html#syntax
"8.1.2.4 Optional tags" is the bit out about it being OK to omit <html>, <head> and <body>
The title element is indeed required, but as Jukka Korpela notes, it also must be non-empty. Furthermore, the content model of the title element is:
Text that is not inter-element whitespace.
Therefore, having just a space character in the title element is not considered valid HTML. You can check this in W3C validator.
So, an example of a minimal and valid HTML5 document is the following:
<!doctype html><title>a</title>
This is the minimal HTML5-valid document:
<!doctype html><title> </title>
W3C HTML validator maintainer here. FYI with regard to the validator behavior, as of today, the validator now enforces the requirement in the HTML spec that the title element must contain at least one non-whitespace character -
http://validator.w3.org/nu/?doc=data%3Atext%2Fhtml%3Bcharset%3Dutf-8%2C%3C%2521doctype%2520html%3E%3Ctitle%3E%2520%2520%2520%3C%252Ftitle%3E
While the <html>, <head> and <body> start and end tags are optional, the <title> tags are required, except in special circumstances, so no, your sample is not (ordinarily) valid.

Where should a site’s language be set?

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

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.