Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are custom HTML attributes not using the data-* prefix valid? [closed]

Tags:

html

angularjs

AngularJS gives the option of, but does not use the data- prefix in their examples or mandate the use of it. Should I include the data- prefix in my project and why?

Is it still valid HTML if I don't use data-*?

like image 270
MR.ABC Avatar asked Jun 13 '13 16:06

MR.ABC


People also ask

Are custom HTML attributes allowed?

The data-* attributes allow us to embed custom attributes on all HTML elements. These are completely ignored by the user agent. The data stored can be used in JavaScript of the page. We can also use these data attributes to style our elements.

What is data -* in HTML?

The data-* attribute is used to store custom data private to the page or application. The data-* attribute gives us the ability to embed custom data attributes on all HTML elements.

Can data -* attribute contain HTML tags?

Certainly. Entities are converted into their values when parsed.

What are the 4 attributes of HTML?

The attribute is most useful with A, AREA, LINK, and IMG elements, where it provides a title for the linked or embedded resource.


1 Answers

Many libraries like knockout, angular etc. do not use the data- prefix.

Knockout uses data-*: "<span data-bind="text: myMessage">"

Angular uses data-*: "the directive can be prefixed with x-, or data- to make it HTML validator compliant" (shame they don't understand that it is for compliance with HTML and not with the validator).

Should i include the data- prefix ?

Yes, you should write valid HTML. If you are making up attributes, use data- ones.

like image 68
Quentin Avatar answered Sep 22 '22 22:09

Quentin