Ari
Ari

Reputation: 3669

What is the proper naming convention for HTML data tags of more than one word?

The custom data attribute in HTML is specified by data-customdataname; In general, I have always named HTML elements containing more than one word by separating them with a dash (e.g. class="foo-bar"). Yet, since the data tag already requires a dash in it, it seems quite impractical to do the same here. I also know that CamelCase is generally not used in HTML names. How should I go about naming a data tag with multiple words?

Upvotes: 2

Views: 1905

Answers (1)

RhinoWalrus
RhinoWalrus

Reputation: 3089

From: http://www.w3.org/TR/2010/WD-html5-20101019/elements.html#custom-data-attribute, "Hyphenated names will become camel-cased. For example, data-foo-bar="" becomes element.dataset.fooBar." As such, I take it that hyphen-separation is the proper convention. Capital letters are also explicitly forbidden in the name, so camel case is out.

Upvotes: 4

Related Questions