Web Components as a Business Decision

web-components javascript
Web Components as a pragmatic UI choice for small teams

Most framework decisions are really hiring decisions, maintenance decisions, and migration risk decisions wearing a technical costume. Web Components are worth understanding not because they're "pure" or "native" -- but because they solve specific business problems that framework-heavy stacks create.

The business case

When you pick React, Vue, or Svelte for a project, you're also picking:

Web Components don't eliminate these concerns, but they change the math. They're a browser standard. They don't ship breaking versions. They work alongside any framework or no framework. And they add zero runtime overhead because the browser already knows how to run them.

What Web Components actually are

Three browser APIs working together:

  1. Custom Elements -- define new HTML tags with your own behavior.
  2. Shadow DOM -- encapsulate styles and markup so components don't leak CSS into (or absorb CSS from) the rest of the page.
  3. HTML Templates -- define reusable markup structures.

A minimal example

class StatusBadge extends HTMLElement {
          constructor() {
            super();
            const shadow = this.attachShadow({mode: 'open'});
            shadow.innerHTML = `
              <style>
                span { padding: 2px 8px; border-radius: 4px; font-size: 0.85em; }
                :host([status="active"]) span { background: #e6f4ea; color: #1e7e34; }
                :host([status="inactive"]) span { background: #fce8e6; color: #c62828; }
              </style>
              <span><slot></slot></span>
            `;
          }
        }
        
        customElements.define('status-badge', StatusBadge);
        

Usage:

<status-badge status="active">Live</status-badge>
        <status-badge status="inactive">Offline</status-badge>
        

No build step. No imports. No package.json entry. It just works in every modern browser.

When Web Components make sense

Web Components are a strong fit when:

When they don't

Be honest about the tradeoffs:

Getting started

  1. Create a class that extends HTMLElement.
  2. Attach a Shadow DOM in the constructor for style encapsulation.
  3. Register it with customElements.define('your-tag', YourClass).
  4. Use it in HTML like any other element.

No build step, no CLI, no starter template. That's not a flex -- it's a genuine reduction in startup cost and ongoing maintenance burden.

The bottom line

Web Components aren't a religion. They're a tool with specific strengths: zero runtime cost, no framework lock-in, excellent browser support, and a standard that won't ship breaking changes. For content sites, internal tools, and design systems that need to last, those properties translate directly into lower cost and lower risk. For complex applications with heavy state management, a framework is probably the right call.

Pick the tool that fits the problem. Ship the thing.

Recommended

Web Components + HTMX: A Lean Architecture for Content Sites That Ship @jameslcowan web-components, javascript
Fixing Navigation and Analytics: When Your Data Lies About User Behavior @jameslcowan htmx, javascript
Mobile-First Layout That Ships: How PrimaryLayout Solves Real UX Problems @jameslcowan htmx, css

Recommended

Web Components + HTMX: A Lean Architecture for Content Sites That Ship @jameslcowan web-components, javascript
Fixing Navigation and Analytics: When Your Data Lies About User Behavior @jameslcowan htmx, javascript
Mobile-First Layout That Ships: How PrimaryLayout Solves Real UX Problems @jameslcowan htmx, css

Search by title, tag, description, or the prose itself. Results appear as you type.