How to create custom tags for HTML [closed]

Depending on what you mean by “special attributes and behavior,” you can “create” custom HTML tags right now. The following shows up in all browsers, and even works with the various JavaScript methods:

<my-book data-pages="400" data-author="Nietzsche">The Wanderer and His Shadow</my-book>

There are just a couple of things you have to keep in mind:

  1. Hyphenation! Custom elements should consist of at least one - like my-book or app-menu or header-title, etc. Just, don’t use data-* since it’s reserved for data- attributes.

  2. All custom elements have a display of inline by default. You can change that with CSS or JavaScript, however.

  3. Internet Explorer does not recognize any of these elements unless you first “create” them with JavaScript:

     document.createElement('my-book');
    

So you have to do that before you can use them in your CSS, HTML, or JavaScript.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)