POST vs post, GET vs get - html

I realize that both will work, but is one more correct than the other?
<form method="POST" />
vs.
<form method="post" />
Why use one or the other?

W3C has tended towards lowercase for attribute names and values for a while.
For example section 4.11 of the xhtml 1.0 standard in 2002:
4.11. Attributes with pre-defined value sets
HTML 4 and XHTML both have some
attributes that have pre-defined and
limited sets of values (e.g. the type
attribute of the input element). In
SGML and XML, these are called
enumerated attributes. Under HTML 4,
the interpretation of these values was
case-insensitive, so a value of TEXT
was equivalent to a value of text.
Under XML, the interpretation of these
values is case-sensitive, and in XHTML
1 all of these values are defined in
lower-case.

You can use either of them why because HTML is not case-sensitive markup language.
See HTML 4.01 Specification
The value is case-insensitive (i.e., user agents
interpret "a" and "A" as the same).
Note that XHTML should be lower case.
4.2. Element and attribute names must be in lower case
XHTML documents must use lower case
for all HTML element and attribute
names. This difference is necessary
because XML is case-sensitive e.g.
<li> and <LI> are different tags.

Either way is fine for HTML. There is not specific recommendation.
Possible (case-insensitive) values are
"get" (the default) and "post".
There are arguments for both uppercase and lowercase. One could say that the default for HTML (and mandatory for XHTML) tokens is to write them in lowercase, but saying that the values used in HTTP requests are the uppercase ones is equally valid.

Either is fine. It's not case sensitive. w3schools implies the w3c recommends lower case for HTML: http://www.w3schools.com/html/html_attributes.asp
Here is the w3c XHTML lower-case requirement for attributes: http://www.w3.org/TR/xhtml1/#h-4.2

As with most coding conventions, consistency is key. Pick the casing you are most comfortable with and make sure to use it throughout your code.

From the HTML 4.01 Recommendation:
This attribute specifies which HTTP method will be used to submit the form data set. Possible (case-insensitive) values are "get" (the default) and "post".
XHTML is different, and the attribute values there are case sensitive and must be lower case.
Under HTML 4, the interpretation of these values was case-insensitive, so a value of TEXT was equivalent to a value of text. Under XML, the interpretation of these values is case-sensitive, and in XHTML 1 all of these values are defined in lower-case.
The above is from XHTML 1.0 (Hat tip to #amelvin for spotting something I assumed was another case of an undocumented change).

Related

Using proper names

My HTML tag specifies lang="en", but there are a lot of proper names in the document. These are such things as surnames, which the validator flags as spelling mistakes. I'd like to put them in a <span> with lang="none" for example. Is there a correct way of doing this (i.e. one which validates as correct HTML?
The correct way to do it is to set the attribute to an empty string
<span lang="">...</span>
To determine the language of a node, user agents must look at the nearest ancestor element (including the element itself if the node is an element) that has a lang attribute in the XML namespace set or is an HTML element and has a lang in no namespace attribute set. That attribute specifies the language of the node (regardless of its value).
If the resulting value is the empty string, then it must be interpreted as meaning that the language of the node is explicitly unknown.
HTML5 Spec

Is an empty class attribute valid HTML?

Is an empty class attribute valid HTML in the following formats:
<p class="">something</p>
<p class>something</p>
I found this question which is similar, but asks specifically about custom data attributes.
After looking at the specifications referred to in the other answers, I have found the sections that actually do answer the raised question.
<p class> is not allowed
The specification on attributes section 3.2.3.1 on Empty Attribute Syntax states the following:
An empty attribute is one where the value has been omitted. This is a syntactic shorthand for specifying the attribute with an empty value, and is commonly used for boolean attributes. This syntax may be used in the HTML syntax, but not in the XHTML syntax.
(...)
This syntax is permitted only for boolean attributes.
Seeing that the description of the class attribute (obviously) does not mention it being a boolean attribute, omitting the value is not permitted.
<p class=""> is allowed
From the section on class we learn that:
Every HTML element may have a class attribute specified.
The attribute, if specified, must have a value that is a set of space-separated tokens representing the various classes that the element belongs to.
and from the definition of space-seperated tokens:
A set of space-separated tokens is a string containing zero or more words (known as tokens) separated by one or more space characters, where words consist of any string of one or more characters, none of which are space characters.
we can conclude that the attribute value can in fact be empty (i.e. containing zero tokens).
From the HTML5 Reference page, section 3.2.3 Attributes:
Elements may have attributes that are used to specify additional information about them. Some attributes are defined globally and can be used on any HTML element, while others are defined for specific elements only. Every attribute must have an attribute name that is used to identify it. Every attribute also has an associated attribute value, which, depending on the attribute's definition, may represent one of several different types. The permitted syntax for each attribute depends on the given value.
So to answer your question,
Invalid:
<p class>
Valid (empty value)
<p class="">
See http://dev.w3.org/html5/html-author/ For all the reference regarding HTML5 you need.
Not having any values won't make it invalid. I have tested it in http://validator.w3.org/#validate_by_input
Put this code there and test:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div class>Validiity
<input type="text" disabled>
</div>
</body>
</html>
Without quotes, just attribute names are drafted for boolean attribute like disabled, required
A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.
More here: https://html.spec.whatwg.org/#boolean-attributes
Read this Q/A on boolean attribute discussion - What does it mean in HTML 5 when an attribute is a boolean attribute?
Class attribute should contain a value. without value its not a valid one. but it shows no impact while rendering.

are attributes without value allowed in HTML4?

I wonder if HTML 4 allows attributes without value, as being equivalent to attributes with an empty value. For example:
<h2 section>foobar</h2>
instead of:<h2 section="">foobar</h2>
Are the two snippets equally valid? If not, are they valid in HTML version 5?
thanks!
Boolean Attributes, Yes they are completely valid.
From W3C: (On SGML & HTML)
Some attributes play the role of boolean variables (e.g., the selected
attribute for the OPTION element). Their appearance in the start tag
of an element implies that the value of the attribute is "true". Their
absence implies a value of "false".
Boolean attributes may legally take a single value: the name of the
attribute itself (e.g., selected="selected").
This states that Boolean attributes are valid in HTML4 as well, but if you use something like, would be invalid.. because that boolean belongs to option tag.. Thanks to #Ronni Skansing for clarifying the doubt..
<p selected>Hello</p>
HTML5 Docs :
From W3C :
Empty Attribute Syntax
Certain attributes may be specified by providing just the attribute
name, with no value.
From W3C: (HTML 5.1 Nightly )
A number of attributes are boolean attributes. The presence of a
boolean attribute on an element represents the true value, and the
absence of the attribute represents the false value.
BUT
section is an invalid attribute, if you want to define your own attributes, HTML5 provides a way to do that.. you need to use data- prefix, for example, your section should be written as data-section, this way your attribute will be counted as valid.
If you hesitate to do so, we always have a validator to check - W3C Markup Validation Service
^ Validated As HTML5
NOTE: Though I provided data- is applicable for HTML5, using custom
attributes in HTML4 is invalid, no matter even if you define data-
before the attribute name, but, boolean attributes are valid in HTML4
as well.
As formally defined, HTML 4 does not allow attributes without a value. What is commonly regarded as attribute without value, as in <input checked>, is formally an attribute value without an attribute name (and an equals sign). Though misleadingly characterized as “boolean attributes” with special minimization rules in HTML 4 specs, those specs normatively cite the SGML standard.
By the SGML standard, whenever an attribute is declared by enumerating keywords that are the only allowed values, an attribute specification may, under certain conditions, be minimized to the value. This means that in HTML 4, the tag <input checkbox> is valid; the attribute is a minimized form of type=checkbox. No browser supports that (they parse checkbox as attribute name), but in validators, the construct passes.
In practice, the part of the attribute minimization rules that browsers support consists of just the special cases where an attribute is declared as allowing a single keyword value only, such as the checked attribute, which is formally declared with
<!ATTLIST INPUT checked (checked) #IMPLIED>
So it depends on how the attribute is declared in the HTML 4 spec.
But this means that the minimized attribute checked means checked=checked. The value is not empty but the keyword checked. On the other hand, browsers treat such attributes as “presence attributes”: what matters is whether an element has that attribute or not, not its value.
In HTML5 serialized as XHTML (i.e., as XML), things are simple: every attribute specification must be of the form name="value" or name='value', so the equals sign is required, and so are the quotation marks; logically, the value is always there, though it can be the empty string, as in alt="".
In HTML5 serialized as HTML, some attributes are defined so that an attribute value (and an equals sign) is not required. Rather confusingly, they are the attributes declared as being “boolean attributes” (it’s confusing e.g. because the values true and false are not allowed, but the name partly reflects the principle that the corresponding DOM property, or “IDL attribute” as they call it, has the truth values true and false as the only permitted values). For such attributes, by definition, the value is even immaterial; only the presence of the attribute matters. For example, for the checked attribute, no value is used, but if a value is given, it must be either the empty string (checked="") or identical with the attribute name, case insensitively (e.g., checked=Checked). Any other value is nonconforming but is required to work, with the same meaning (e.g., checked=false means the same as checked).
Regarding the specific example, it is not valid in any version of HTML, since there is no attribute section declared.
Both snippets are syntactically valid in html4 and html5. The first is not valid xhtml, because in xhtml an attribute value is required.
On the other hand, section is not a defined attibute, but it is a valid tag in html5. Therefore your code is not valid.

Is there any difference for data-attribute=false with data-attribute="false" in html element?

I have data attribute in html element as <button data-verified=false>Update</button>. It have boolean value for data attribute.
Is there any difference with following element <button data-verified="false">Update</button> as the data-attribute is wrapped with double quotes.
Is boolean values are supported in html?
Boolean attributes are supported in HTML, but data-verified isn't one of them, no matter how it appears in the markup. data-verified=false and data-verified="false" both create an attribute of the type string and value "false", which if tested in JS as a boolean will be treated as true
This is only the case because false doesn't contain spaces. As a contrary example, data-verified=not true is invalid and not at all the same as data-verified="not true"
There are no differences in the values - however, always prefer to quote around attribute values, because:
Looks cleaner
Easier to maintain
Every editor can deal with it easily
It's a standard, nearly all HTML code examples you'll see use the value quoted
My answer corroborates from Do you quote HTML5 attributes?
I think it is just a convention that attributes always have double quotes.
However. In jQuery, you can use the .data() method. It is smart enough to recognize booleans and numeric values.
The only difference is that only the latter is allowed in XHTML. In HTML syntax, they both are allowed, and they are equivalent: the difference is lost when the HTML markup is parsed, and the DOM contains in both cases only the string false.
This follows from general principles in HTML and does not depend on the name of the attribute in any way.
“Boolean value” is a vague term. In HTML5, some attributes are called “boolean attributes”, but this is strongly misleading – especially since values true and false, far from being the only values allowed, aren’t allowed at all for such values. You need to read the specification of “boolean attributes” to see what they really are.
When you use data-* attributes, it is completely up to you what you use as values and how you process them.

Is it not anymore necessary to enclose the values of attributes in HTML5 with quotes?

I am trying to learn HTML5 and I saw some tutorials that do something like:
<input type=email>
And I noticed that it differs from XHTML where most values (if not all) should be enclosed in quotes.
Will this have any future things that I have to take caution of?
I'll refer you to the specification: http://www.w3.org/TR/html5/syntax.html#attributes-0
Attributes can be specified in four different ways:
Empty attribute syntax
Unquoted attribute value syntax
Single-quoted attribute value syntax
Double-quoted attribute value syntax
HTML has never required quoting attribute values (it is optional). XHTML has always required quoted attribute values. HTML5 carries on this tradition.