Search code examples
htmlcsscustom-element

Do we need to register Custom Tag?


I have been reading this article about HTML5 Custom Element.

It said I need to register the element's name before using it like:

var XFoo = document.registerElement('x-foo');
document.body.appendChild(new XFoo());

Then I can start using it normally:

<x-foo>...</x-foo>

But I just tried using it without registering in Chrome, Firefox, and IE11. All seems to render just fine, even CSS selector for x-foo also works.

I'm guessing that we no longer need to register since most browsers have supported it?

Thanks


Solution

  • Short answer: No.

    As a good practice, always define things that are not official. Just because it works by all/most browsers does not make it correct. That would be similar to using a variable which is yet to be defined, and then the compiler automatically defining it. Sure, it works, but that does not make it right