Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a size limit for data- attributes? [duplicate]

How long is too long for an attribute value in HTML?

I'm using HTML5 style data attributes (data-foo="bar") in a new application, and in one place it would be really handy to store a fair whack of data (upwards of 100 characters). While I suspect that this amount is fine, it raises the question of how much is too much?

like image 782
nickf Avatar asked Nov 25 '22 17:11

nickf


1 Answers

HTML5 has no limits on the length of attribute values.

As the spec says, "This version of HTML thus returns to a non-SGML basis."

Later on, when describing how to parse HTML5, the following passage appears (emphasis added):

The algorithm described below places no limit on the depth of the DOM tree generated, or on the length of tag names, attribute names, attribute values, text nodes, etc. While implementors are encouraged to avoid arbitrary limits, it is recognized that practical concerns will likely force user agents to impose nesting depth constraints.

Therefore, (theoretically) there is no limit to the length/size of HTML5 attributes.

See revision history for original answer covering HTML4.

like image 99
bobbymcr Avatar answered Jan 16 '23 21:01

bobbymcr