Web Component Example: Just Some HTML
This is a super basic Web Component. All it does is output some HTML.
JavaScript
class Widget extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
this.content = document.createElement('div')
this.content.innerHTML = 'This is a web component'
this.shadowRoot.append(this.content)
}
}
customElements.define('wc-widget', Widget)
HTML
<wc-widget></wc-widget>
Output