Even the new HTML5 tags aren\'t enough to describe structures without falling back to div
s. What\'s stopping me from changing:
One reason is that Internet Explorer (and earlier versions of Firefox) don't have a fallback for tags that are not defined and wind up ignoring them for both styling and nesting. Without a shiv, your site will break horribly in those browsers.
getElementsByTagName fails me with custom tags. Example,
<acme:mytag id="mytag">
<div id ="x">x</div>
<div id ="y">y</div>
<div id ="z">z</div>
</acme:mytag>
This fails with IE8 (Quirks Mode or Standard Mode)
var mytag = document.getElementById('mytag'); // it's found
var mydivs = mytag.getElementsByTagName ('div'); // but this is always 0
Unless your html tag reads
<html XMLNS:acme>
...
</html>
What is the goal of the tags you chose? If your goal is to present information, then using divs and other presentation-oriented structures is great. Your tags look more like they are attempting to describe the actual data. If that is the case, then XML with XSLT transforms on the server side to output HTML for presentation markup is best. Remember that a browser is simply a rendering engine and it uses the HTML spec as it's blueprint of what to render for a given site. The browser doesn't need to understand the information like a "post" or "userInfo" because it has no context for undertsanding what to do from a rendering perspective with that information. CSS can help a browser understand what you want to do visually but ask yourself first whats the goal of having your markup that way, to store your data (XML-style) or to present it. If to present it, then you should go with the standards if you want to continue to use a browser as your rendering engine. Good luck, would be great if we could all define our presentation schemes though, fun idea!
display
property is not implied either so give it a value, but after that, everything is as usual. DOM contains your node, querySelector
works, styles apply, etc.Self-closing or not - to make your tag self-closing, use the good old <something/>
format, as you would with <br/>
for example. It's important, otherwise browsers go look for the closing tag. I mean, how could they not.
Future collisions - that's the only good point from custom tag skeptics: just as we have a lot of new tags in HTML5, it's a possibility that you name a tag "icon" and it will mean something in the next HTML standard, even with a bunch of rendering defaults, and that can mess your page up badly. So I'd say, if you want to be on the safe side, use <dashed-names>
for your tags, they will never ever mess with dashed tag names thanks to the naming of Web Components. Also check out § 4.13 in HTML standard itself.
Blame magnet effect - seriously, that's an issue with custom tags, I've been down this road. Use custom tags only if everyone working on the same project is on board with it. Otherwise, whenever something breaks it will be your fault "because of your stupid custom tags", and you'll have to change every instance to the usual <div class="gurgleburgle">
, only to find later that the real issue was totally unrelated.
TLDR:
<custom-tags> Yes you can use them </custom-tags>
Most browsers will just treat the tags as arbitrary (like how old browsers treat HTML5 tags). Nothing is stopping you from using your own tags, but it's not a well-accepted way to code HTML. HTML is supposed to use pre-defined tags.
If you're interested in coding with arbitrary tags, you could just go with XML. You can format XML with XSLT (used in a way similar to stylesheets, but much more powerful). Have a look here: http://www.w3schools.com/xml/xml_xsl.asp
The issue is that it would not validate and the new tags would simply be ignored.