Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I just make up attributes on my HTML tags?

Am I allowed to add whatever attributes I want to HTML tags such that I can retrieve their value later on using javascript? For example:

<a href="something.html" hastooltip="yes" tipcolour="yellow">...</a> 

If that's not going to work, how would you store arbitrary pieces of information like this?

Edit: Since it appears that making up HTML attributes isn't technically valid, I've rephrased the second part of this question into its own question here: How to store arbitrary data for some HTML tags

like image 827
nickf Avatar asked Jan 09 '09 06:01

nickf


People also ask

Can you make up your own attributes in HTML?

If you want to define your own custom attributes in HTML, you can implement them through data-* format. * can be replaced by any of your names to specify specific data to an element and target it in CSS, JavaScript, or jQuery.

Can I make up tags in HTML?

There you can invent your own tags. In Xhtml and HTML < 5 it's just invalid markup. However you will have to close the body-tag and wrap the whole markup in html-tags.

Can attributes stand alone in HTML?

Attributes. Attributes are added within a tag to extend or modify the tag's actions. Attributes always go in the start tag only (end tags never contain attributes). You can add multiple attributes within a single tag.

How do you write attributes in HTML?

The title attribute (and all other attributes) can be written with uppercase or lowercase like title or TITLE. However, W3C recommends lowercase attributes in HTML, and demands lowercase attributes for stricter document types like XHTML. At W3Schools we always use lowercase attribute names.


1 Answers

In HTML5, yes. You just have to prefix them with data-. See the spec.

Of course, this implies you should be using the HTML5 doctype (<!doctype html>), even though browsers don't care.

like image 193
Ms2ger Avatar answered Oct 07 '22 15:10

Ms2ger