[whatwg] Custom attributes [was: Adding a src attribute to all elements]

Markus Ernst derernst at gmx.ch
Wed Nov 4 02:57:43 PST 2009


Michael A. Puls II schrieb:
> On Wed, 04 Nov 2009 05:03:49 -0500, Markus Ernst <derernst at gmx.ch> wrote:
> 
>> Tab Atkins Jr. schrieb:
>> On Tue, Nov 3, 2009 at 8:21 PM, Michael A. Puls II 
>> <shadow2531 at gmail.com> wrote:
>> On Tue, 03 Nov 2009 21:05:26 -0500, Curtiss Grymala <curtiss at ten-321.com>
>> wrote:
>> For instance, if I create a level 1 header that looks like:
>> <h1 src="/example.png">This is a header</h1>
>> The text "This is a header" would be replaced with the image that's
>> located at /example.png. However, if /example.png returns a 404 error,
>> the text would be displayed instead.
>> Opera supports this with css extensions.
>>  This is supported in the CSS specs properly, via the content property.
>>  *[src] {
>>   content: attr(src,url);
>> }
>>  If I understand things correctly, your example seems a little bit 
>> confusing to me. The *[src] selector selects elements with a src 
>> attribute specified, which does not apply to <h1> (if valid HTML5)
> 
> *[data-my-src] {}
> <h1 data-my-src="">

While experimenting with the validator (at validator.w3.org), I found 
that it does actually not complain about <h1 src="whatever.gif">. Thus, 
Tab's example would be perfectly valid. The validator even seems to 
accept any custom attribute name on any element - this is said to be 
valid HTML5:

<!doctype html>
<html>
<body>
<h1 foo="bar">Huhu</h1>
</body>
</html>

I tried to find info about this in the spec, but only found:

3.2.1: Authors must not use elements, attributes, and attribute values 
that are not permitted by this specification or other applicable 
specifications.

3.2.3: Custom data attributes (e.g. data-foldername or data-msgid) can 
be specified on any HTML element, to store custom data specific to the page.

According to 3.2.3.8 custom data attribute names must begin with 
"data-". I did not find anything on other custom attributes allowed.

Is this a mistake in the validator, due to its experimental state, or is 
there something missing in the spec?



More information about the whatwg mailing list