Skip to content

Instantly share code, notes, and snippets.

Last active Dec 8, 2021
What would you like to do?
Potential future with ES Modules and Web Components (multi-file version)
main fancy-article::part(header) {
color: red;
aside fancy-article::part(header) {
color: blue;
import {FancyArticle} from 'fancy-article';
window.customElements.define('fancy-article', FancyArticle);
:host {
padding: 1rem;
background-color: #fff;
border-radius: 0.5em;
font-size: 1rem;
::slotted([slot="title"]) {
color: #333;
font-weight: 900;
font-size: 2em;
<article-header part="header">
<slot name="title">TITLE</slot>
<slot name="description">DESCRIPTION</slot>
import {content} from './fancy-article.html';
import sheet from './fancy-article.css' assert { type: 'css' };
export class FancyArticle extends HTMLElement {
constructor() {
this.attachShadow({ mode: 'open' });
// Adopt the stylesheet
this.shadowRoot.adopedStyleSheet = [sheet];
// Use the template
this.shadowRoot.appendChild(document.importNode(content, true));
"imports": {
"app": "/app.mjs",
"fancy-article": "/fancy-article.mjs"
<!doctype html>
<meta charset="utf-8">
<link rel="stylesheet" href="app.css">
<script type="importmap" src="/importmap.json"></script>
<script async type="module">import 'app';</script>
<h1 slot="title">Hello, World!<h1>
<p slot="description">
I am a Web Component.
<h2 slot="title">Another Fancy Article<h2>
<p slot="description">
I am another one with a different heading level.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment