SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Naturally custom attributes will make your code invalid. If it is not part of the specs how can it be valid? Browsers should ignore it so it shouldn't affect the page's rendering.
    Last edited by stymiee; Dec 12, 2006 at 08:04.

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    Robert Wellock silver trophybronze trophy xhtmlcoder's Avatar
    Join Date
    Apr 2002
    Location
    A Maze of Twisty Little Passages
    Posts
    6,316
    Mentioned
    60 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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)?
    Simon Pieters

  6. #6
    SitePoint Member
    Join Date
    Dec 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm about to implement custom attributes sitewide for our company. We use a lot of client side logic. I will be 'namespacing' these attributes as to not conflict with possible future standards.

  7. #7
    SitePoint Addict
    Join Date
    Sep 2004
    Location
    Denver
    Posts
    385
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what are you meaning by namespacing?

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Is it really that important to be 100&#37; valid? Will adding a custom attribute break the browser? No it won't the browser will just ignore it like everything else it doesn't know.

    Not to say there might be a bug that emerges in a browser but that wouldn't be HTML's fault.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    Will adding a custom attribute break the browser?
    Probably not, but you can't know for sure what will happen.
    Quote Originally Posted by logic_earth View Post
    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="").
    Simon Pieters


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •