Skip to content
Skills Library
Programming · Building & coding

web-components-custom-elements

/web-components-custom-elements

Use this skill when authoring framework-agnostic Custom Elements, Shadow DOM encapsulations, and HTML templates using the Web Components standard.

Licence
MIT
Last repository change
28.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 28.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Use this skill when authoring framework-agnostic Custom Elements, Shadow DOM encapsulations, and HTML templates using the Web Components standard.

Original author description

Use this skill when authoring framework-agnostic Custom Elements, Shadow DOM encapsulations, and HTML templates using the Web Components standard.

How it works

  1. When to use
  2. Prerequisites
  3. Step-by-step workflow
  4. Commands / code examples
  5. Common mistakes & pitfalls
  6. Verification checklist
  7. Related skills
Original SKILL.md headings · 82 lines, 370 words
SKILL.md preview
---
name: web-components-custom-elements
description: Use this skill when authoring framework-agnostic Custom Elements, Shadow DOM encapsulations, and HTML templates using the Web Components standard.
---
# Web Components and Custom Elements

## When to use
Use this skill when building reusable, framework-independent UI widgets, micro-frontend building blocks, or shared enterprise component libraries.

## Prerequisites
- Deep familiarity with modern JavaScript (ES6+ classes, lifecycle callbacks).
- Understanding of the DOM tree, events, and CSS encapsulation.

## Step-by-step workflow
1. **Extend HTMLElement**: Create an ES6 class extending `HTMLElement`.
2. **Attach Shadow DOM**: In the `constructor`, call `super()` and attach a shadow root using `this.attachShadow({ mode: 'open' })`.
3. **Implement lifecycle methods**: Connect behaviors inside `connectedCallback`, `disconnectedCallback`, and `attributeChangedCallback`.
4. **Declare observed attributes**: Provide a static `get observedAttributes()` getter returning an array of tracked attribute strings.
5. **Register the custom element**: Call `customElements.define('my-element', MyElement)` ensuring the tag name contains a mandatory hyphen.

## Commands / code examples
```ts
class StatusBadge extends HTMLElement {
  static get observedAttributes() {
    return ['status'];
  }

  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
  }

  connectedCallback() {
    this.render();
  }

  attributeChangedCallback(name: string, oldValue: string, newValue: string) {
    if (oldValue !== newValue) {
      this.render();
    }
  }

  render() {
    if (!this.shadowRoot) return;
    const status = this.getAttribute('status') || 'offline';
    const isOnline = status === 'online';

    this.shadowRoot.innerHTML = `
      <style>
        :host { display: inline-block; font-family: system-ui, sans-serif; }
        .badge {
          display: inline-flex; align-items: center; gap: 0.375rem;
          padding: 0.25rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500;
          background: ${isOnline ? '#dcfce7' : '#f3f4f6'};
          color: ${isOnline ? '#166534' : '#374151'};
        }
        .dot { width: 6px; height: 6px; border-radius: 50%; background: ${isOnline ? '#22c55e' : '#9ca3af'}; }
      </style>
      <span class="badge">
        <span class="dot"></span>
        <slot>${status}</slot>
      </span>
    `;
  }
}

customElements.define('status-badge', StatusBadge);
```

## Common mistakes & pitfalls
- Forgetting the required hyphen in custom element tag names (e.g., using `<badge>` instead of `<status-badge>`).
- Performing DOM rendering or accessing child elements inside the `constructor` instead of `connectedCallback`.
- Forgetting to clean up global event listeners attached outside the shadow root in `disconnectedCallback`.

## Verification checklist
- [ ] Element tag name contains at least one hyphen (`-`).
- [ ] Shadow DOM is initialized in `constructor` and rendered in `connectedCallback`.
- [ ] Tracked attributes are listed in `static get observedAttributes()`.
- [ ] Component cleans up timers and listeners when disconnected from the DOM.

## Related skills
- browser-dom-manipulation-events
- html5-semantic-web
- micro-frontends-module-federation
- javascript-es2024-deep-dive

Versions

The database has no other skills named web-components-custom-elements.

Database snapshot: 13.11.2026 · package version 4cee9b31d1f8 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90frontend-web-components
    Use this skill when the user says 'web component', 'custom element', 'shadow DOM', 'HTML template', 'CustomElementsRegistry', 'ElementInternals', 'form-associated element', 'cross-framework component', 'vanilla web component'. This skill enforces: custom element lifecycle…
  • 90fe-web-components
    Writes and reviews custom elements, plain or with Lit 3 - names, lifecycle, attributes and properties, shadow DOM styling, events, form-associated controls with ElementInternals, accessibility across the shadow boundary. Use when defining a custom element, writing a LitElement,…
  • 90frontend-lit
    Use this skill when the user says 'Lit', 'LitElement', 'lit-html', 'web component Lit', 'reactive element', '@lit/reactive-element', 'Lit SSR', 'Lit component', 'Lit decorator', 'Lit reactive property'. This skill enforces: LitElement base class with reactive properties,…
  • 100html5-semantic-elements
    Use when reviewing templates, rendered HTML, or shared components related to Use semantic HTML elements. Validate the final browser-facing markup, not just the source framework abstraction.
  • 100lit-doctor
    Use when editing, reviewing or debugging code that imports lit, lit-element or lit-html - even a small change to one component, a property that is not rendering, a value derived before render, `[object Object]` in a template, shadow DOM lookups in tests, or a slow or janky…
  • 95migrate-swc-gen1-to-gen2
    Upgrade Spectrum 1 (sp-* elements, @spectrum-web-components/*) to Spectrum 2 (swc-* elements, @adobe/spectrum-wc). Use when developers need to migrate from Spectrum 1 to Spectrum 2 web components, or when they mention @spectrum-web-components, sp-* elements, or Spectrum 1.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.