42

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?

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405

6 Answers6

41

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.

amelvin
  • 8,919
  • 4
  • 38
  • 59
14

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.

Sygmoral
  • 7,021
  • 2
  • 23
  • 31
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
  • 2
    It's worth noting that XHTML (note the X) *is* case-sensitive - tags and attribute names should all be lower-case. That said, I'm not aware of case-restrictions on well-defined attribute *values*. – RobM Nov 05 '10 at 14:06
  • Is this not down to the doctype? because XML requires lower-case. – RobertPitt Nov 05 '10 at 14:07
  • @RobM: It is good that you mentioned XHTML standard, though here I meant HTML 4.01 specification: http://www.w3.org/TR/html4/interact/forms.html#adef-method. Update the answer though :) – Sarfraz Nov 05 '10 at 14:09
  • @Sarfraz regarding you XHTML edit. That quotation states that attribute names should be in lower-case, not attribute values. – Alin Purcaru Nov 05 '10 at 14:15
  • @Alin Purcaru: Attribute values should also be lower case if you could browser through the docs :) `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.` – Sarfraz Nov 05 '10 at 14:16
  • 2
    @Sarfraz See amelvin's answer. Attribute values (not names!) should be in lowercase only for predefined values. You can't say that having `id="MYID"` is not valid XHTML. – Alin Purcaru Nov 05 '10 at 14:19
  • @Alin Purcaru: I think it says the same thing, in xhtml, attribute values should be lower case ;) – Sarfraz Nov 05 '10 at 14:22
  • No they shouldn't. Pay attention. I even gave you an example. You have to make a distinction between attribute names and attribute values. `name="value"`. – Alin Purcaru Nov 05 '10 at 14:25
  • 3
    `Comment by David Dorward` — I'd rather not see proper nouns made lower case! The words **these values** are important, it limits the rule to *enumerated attributes* (as opposed to all attributes). – Quentin Nov 05 '10 at 19:38
8

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.

Alin Purcaru
  • 43,655
  • 12
  • 77
  • 90
4

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

kanaka
  • 70,845
  • 23
  • 144
  • 140
  • 7
    w3schools in in no way affiliated with w3c! – Alin Purcaru Nov 05 '10 at 14:06
  • 2
    Eugh. I wish W3Schools had bothered to link to that recommendation, because I can't find it anywhere. In general, avoid W3Schools. They are highly error prone. – Quentin Nov 05 '10 at 14:08
  • @Alin — I'd normally be shouting that myself, but the cited page states that the W3C makes that recommendation (although it doesn't say where they do). The answer could be better worded to avoid the implication though. – Quentin Nov 05 '10 at 14:09
  • Well, as you can see from the links posted in my answer and that of others, w3c says both are equally fine and if you take a look through the chapter about forms you will see both forms used. – Alin Purcaru Nov 05 '10 at 14:11
  • No, the link you posted shows that W3Schools claims that the W3C says they are both equally find. Since W3Schools are untrustworthy, that isn't very helpful. – Quentin Nov 05 '10 at 14:12
  • But don't forget that real request should be sent with POST or GET method name, it is case sensitive. Proxies may not allow low case methods names. – Illarion Kovalchuk Nov 05 '10 at 14:21
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.

DJ Quimby
  • 3,669
  • 25
  • 35
2

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

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks for the hat tip - knowing these attribute values can be called 'enumerated attributes' was interesting (if retrospectively obvious). – amelvin Nov 05 '10 at 14:18