Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad practice to use custom elements in HTML5? [duplicate]

Using stuff like document.getElementByTagName, you can practically create your own elements.

<arial>Hello</arial>

And then in JS..

var a = document.getElementsByTagName("arial");

for(i = 0; i < a.length; ++i)
     a[i].style.fontFamily = "Arial"

And we have a custom element, easy peasy.

My question comes down to, is this bad practice? Is there some drawback I'm not noticing?

like image 507
bobbybee Avatar asked Aug 11 '13 22:08

bobbybee


People also ask

Is it OK to use custom HTML tags?

It is completely safe to use custom HTML tags in your web project. With their excellent browser support and ease of use, nothing is stopping you from using them today. Just remember to make custom tags block-level elements if you're using them for page structure.

Can we use custom attributes?

Custom attributes are attributes that are not part of the standard HTML5 attributes but are explicitly created. They allow us to add our own information to HTML tags. These are not specific and can be used with all the HTML elements.

How do custom elements work?

Custom Elements are a feature of modern browsers which allow you to modularise and install your JavaScript components into the browser itself in order to extend it in new and powerful ways. Custom Elements are HTML components which have their own self-contained markup, styling and behaviour.

What can HTML5 do as a new feature?

Audio and Video tags are the two major addition to HTML5. It allows developers to embed a video or audio on their website. HTML5 video can use CSS and CSS3 to style the video tag. You can change the border, opacity, reflections, gradients, transitions, transformations, and even animations.


1 Answers

The W3C says you should not. It is bad practice.

Authors must not use elements, attributes, or attribute values that are not permitted by this specification or other applicable specifications, as doing so makes it significantly harder for the language to be extended in the future.

Furthermore, HTML5 is not XML. You should only use the elements outlined in the official spec.

like image 193
Michael Irigoyen Avatar answered Sep 18 '22 06:09

Michael Irigoyen