html - Is it ok to define your own tags in HTML5? -
this question has answer here:
- using custom html tags 9 answers
in html5, ok use css define own tags? know can looked on bad practice, why? , why isn't there xhtml5 developers can use?
edit===========================================================edit asked how 1 define own tags, here example. wanted move text right 10 pixels. have several options:
<li> ectmoveright, , put in css: moveright {margin-left:10px;}in cases, use div class, if have many times, may want use last option, save myself typing. so, in short laziness. and, loves html5, xml, , css3!
as of today, no not okay define own html5 tags. html5 spec explicitly forbids it. reason avoid potential clashes official html5 tags added in future , people's custom tags.
in practice, can it; pretty every browser out there allow it, , work, you'll breaking spec.
however there spec amendment going through works @ moment aimed @ allowing it. spec not finalised yet, it's being used few people.
the new spec says if want define own tags, it's fine; add x- front of tag name.
so create <x-mytag> rather <mytag>.
i suggest keeping eye on w3c specs see when finalised, , whether make last minute changes, now, i'd run that.
however, bear in mind intended use creating widgets. in other words, if you're building own combo-box or tree view control, example. not intended arbitrarily creating new tags in document flow -- have classes in html already; if you're doing element basic styling, use div class.
hope helps.
references:
current spec: http://www.w3.org/html/wg/drafts/html/master/dom.html#elements
authors must not use elements, attributes, or attribute values not permitted specification or other applicable specifications, doing makes harder language extended in future.
-
this article job of explaining how create custom elements comply new spec. required reading if want sort of thing.
but aware of warning @ top of article echos own in answer:
heads up! article discusses apis not yet standardized , still in flux. cautious when using experimental apis in own projects.
related question: are custom elements valid html5?
Comments
Post a Comment