Farjad Babar
Farjad Babar

Reputation: 53

Custom Attributes in HTML elements

My question is simple

How many custom attributes we can use in a element e.g

<input value="1" vcFlag="true" name="example" />

I am using vcFlag="true" as custom attribute how many attributes like this I can put in this input element. Is there any limit or not.

thanks

Upvotes: 1

Views: 2056

Answers (2)

Adriano Repetti
Adriano Repetti

Reputation: 67148

There is no (theoric) limit to the number of attributes you can add to a HTML tag:

Every HTML element may have any number of custom data attributes specified, with any value.

Attribute parsing is slower than node parsing so if you use a huge number of custom attributes you may slow down page parsing, specially on some old browsers.

Just rmember to prefix them with data- to be HTML 5 compatible: Data Attributes on W3C Working Draft.

In your case it should be:

<input value="1" data-vcFlag="true" name="example" />

Upvotes: 3

Jordizle
Jordizle

Reputation: 252

There is no limit for custom attributes.

Thanks to HTML5, we now have the ability to embed custom data attributes on all HTML elements, these new custom data attributes consist of two parts:

Attribute Name :

The data attribute name must be at least one character long and must be prefixed with 'data-' and should not contain any uppercase letters.

Attribute Value :

The attribute value can be any string.

HTH

Upvotes: 1

Related Questions