The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

custom html attributes

Greetings, I'm intersted in adding some custom html attributes to some of my html elements. for example, say I'm writing some JS code to validate a field and I would like to have my input fields have a required attribute similar to this
<input type="text" id="txt1" required="true" />
As a general rule, are there any disadvantages to using custom attributes like that? would my xhtml still be valid? how about browser compatibility? Any thoughts are appreciated. Thanks.

Customised DTD do not make you code invalid at all I as have produced some and they do validate with the W3C Validator.

With XHTML all you have to achieve is 'well-formedness' the disadvantages are no mainstream browser reads customised DTD so it won't understand what you are writing. Thus under normal circumstances you gain very little. Though some programs and XML Processors do Validate against or customised DTD and use them appropriately.

But being DTD-valid is meaningless. It tells nothing about conformance.

The disadvantage of using custom attributes is that if enough pages use them then HTML can't introduce new attributes. You know, what if "the next version of HTML" added the required="" attribute (which, by the way, is very likely)?

No it won't the browser will just ignore it like everything else it doesn't know.

It's true that browsers ignore things they don't know, but you can impossibly know which attributes future browsers know and don't. So, as I said in reply #5, when browsers start implementing some new HTML standard your page with custom attributes might not work as you intended (because the new HTML standard has defined special semantics to that very attribute).

This has already happened, where Opera 9 implemented Web Forms 2.0 and some pages used a required="" attribute on form controls even though the controls weren't actually required (so the form couldn't be submitted).

So, to prevent this you shouldn't use custom attributes, and if you really "need" to anyway (despite being strongly discuraged) you should use some prefix to your attributes (like foo-required="" instead of required="").