0

How can i create own tag in HTML ??

how we can add our own tag in html like for example.. <my>hii</my>

6th Jan 2019, 5:04 PM
Dharmesh Pandey
Dharmesh Pandey - avatar
10 Answers
+ 7
Gordon Why should this practice be discouraged? Dharmesh Pandey You can implement custom elements natively in most modern HTML5 browsers with Web Components. https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements You can also use transpilers like Babel to convert view templates like ESX in ReactJS and VueJS which are built on the concept of custom components. A third option is implementing ES6 classes that extend existing DOM Elements.
6th Jan 2019, 5:46 PM
David Carroll
David Carroll - avatar
+ 3
Don't do that
6th Jan 2019, 5:26 PM
Gordon
Gordon - avatar
+ 3
HTML5 supports custom elements. Check out an sample code here https://code.sololearn.com/WoagNgG5fo2e/?ref=app
6th Jan 2019, 5:59 PM
CalviŐ˛
CalviŐ˛ - avatar
+ 3
CalviŐ˛ Nice demo! Dharmesh Pandey I suppose there isn't anything actually stopping you from just using a custom HTML element. You could just add something like: <test>test</test> Which could still be styled with CSS and accessible via the DOM API. However, there might be some limitations or inconsistent behaviors from browser to browser.
6th Jan 2019, 8:55 PM
David Carroll
David Carroll - avatar
+ 2
Wow, I didn't know these. Glad that you give a correct answer~ Let me test this new knowledge 😋
6th Jan 2019, 5:51 PM
Gordon
Gordon - avatar
+ 2
Gordon Not that I'm aware of. Why do you ask?
7th Jan 2019, 1:32 PM
David Carroll
David Carroll - avatar
+ 1
Is there actually a naming rule for the custom element that it must contain hyphen? https://code.sololearn.com/WTZmYfd6ne0w/?ref=app
7th Jan 2019, 9:53 AM
Gordon
Gordon - avatar
+ 1
I tested. Console logs error: Failed to execute 'define' on 'CustomElementRegistry': "try4" is not a valid custom element name Later tryfive is not allowed too. I checked MDN example and Calvin's example, so I guess the name must have a hyphen 🤔
7th Jan 2019, 1:39 PM
Gordon
Gordon - avatar
+ 1
Thanks. And yes the unregistered tags are really "HTMLUnknownElement". Wow~
7th Jan 2019, 1:56 PM
Gordon
Gordon - avatar