[web] Custom HTML Tags

Started by
8 comments, last by ID Merlin 15 years, 1 month ago
I was recently experimenting with making my own HTML tags using CSS stylesheets and I got some pretty satifying results. For example, I can do the following: <style type="text/css"> foo { padding: 2px; font-size: 12px; font-family: Verdana; background-color: silver; border: 1px solid gray; } </style> <foo>This is a custom tag.</foo> I think this is really cool because I can annoy fellow developer with stuff like this! Just kidding! :) Anyways, I was wondering how well custom tags are supported across browsers. Any ideas?

Codeloader - Free games, stories, and articles!
If you stare at a computer for 5 minutes you might be a nerdneck!
https://www.codeloader.dev

Advertisement
That's like getting on your knees and begging for trouble.

Link found with google

Technically, there is a specific set of tags that are part of (X)HTML standards. Weird things you do on top of that are undefined.

If you are interesting in creating your own tags, you might look into XML for the web and XSLT. Eventually, you will still have to convert your custom tags into something standard for browsers to read. Given all that trouble, it's usually best just to write standard HTML.
Quote:Original post by leiavoia
That's like getting on your knees and begging for trouble.

Link found with google

Technically, there is a specific set of tags that are part of (X)HTML standards. Weird things you do on top of that are undefined.

If you are interesting in creating your own tags, you might look into XML for the web and XSLT. Eventually, you will still have to convert your custom tags into something standard for browsers to read. Given all that trouble, it's usually best just to write standard HTML.


Never really used the blink tags, but, nevertheless, it's quite interesting and fun to make your own tags.

Codeloader - Free games, stories, and articles!
If you stare at a computer for 5 minutes you might be a nerdneck!
https://www.codeloader.dev

Just do:

<style type="text/css">
div.foo {
}

span.bar {
}
</style>

<div class="foo">a</div>

<span class="bar">b</span>
Yeah, what Kon presented is 10x more dev-appropriate.
Haha. I got warned because of a rickroll.
Quote:Original post by konForce
Just do:

<style type="text/css">
div.foo {
}

span.bar {
}
</style>

<div class="foo">a</div>

<span class="bar">b</span>


I know about this. I develop web sites. After experimenting, I found that IE is unable to recognize custom HTML tags without modification of the DTD. Interesting!

Codeloader - Free games, stories, and articles!
If you stare at a computer for 5 minutes you might be a nerdneck!
https://www.codeloader.dev

There is no such thing as a custom HTML tag. The list of HTML tags is fixed by several standards (such as this one).

If you include any tag that is not covered by one of these standards in your document, then the document is not valid HTML anymore—this may mean that the browser displaying your document may do anything with it. Some will ignore the tags, others will incorporate them in the displayed XML tree without checking whether they are valid.

If you want to see how the various brosers react, take a look at browsershots. But there is no official support for these things.
The 'custom tags' won't work at all in IE - it parses each tag into an empty element (one named "FOO", one named "/FOO"). If you write <script>document.createElement('foo')</script> then IE will start parsing <foo> into an element with content, but that's totally evil. Other browsers parse the tags kind of like <span> or <div>, but they all do it slightly differently (e.g. Firefox 2 doesn't let you put block elements inside custom tags, but that was fixed in Firefox 3).

(DTDs are irrelevant - browsers ignore them entirely. You might trick the validator into saying your document is okay, but that's a waste of time.)

For your own sanity, don't use custom tags [smile]

Quote:If you include any tag that is not covered by one of these standards in your document, then the document is not valid HTML anymore—this may mean that the browser displaying your document may do anything with it.
The HTML 5 draft does cover unknown tags, and requires them to be parsed identically to <span> (via the "Any other start tag" steps). Mozilla, Apple and Opera have indicated that implementing the HTML 5 parsing algorithm is a long-term goal, so hopefully they will converge on that behaviour. (No idea what Microsoft plans to do, though.)
Quote:No idea what Microsoft plans to do, though


Knowing them, they will probably come up with something by the time IE10 rolls around by 2025 [grin]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

Still, annoying your fellow developers has some merit, in an evil, twisted way.

This topic is closed to new replies.

Advertisement