completefrontend
Open lab My progress
THE WEB COMPONENTS FIELD GUIDE

Using a component library

Learn how to use a web component library: load Web Awesome from a CDN or npm, let its autoloader fetch tags, and read a component's docs.

By the end, you can
  • 01
    Add a library to a pageLoad Web Awesome from its CDN with two lines, or install it with npm and load the same files from node_modules.
  • 02
    Know what the autoloader loadsSay how it finds wa- tags and loads each one's file, and when to import a component's file yourself.
  • 03
    Read a component's docsFind a tag's attributes, slots, events, methods, custom states, and CSS parts in its docs, and use each one on a page.

How do you use a web component library?

Ravi looks after the websites of Leaf and Kettle, the tea shop from the last lesson. On Monday, the owner asks for a new menu page by Friday. It needs buttons, a card for each tea, and a box that pops up to say thank you.

Ravi's tea kit has three first drafts: a label, a price, and a card. A good pop-up box takes much longer. It has to work with the keyboard, close with the Escape key, and make sense to screen readers. Does Ravi have to build all of that first?

No. To use a web component library, you add its stylesheet and its script to your page. Then you write its tags in your HTML, like any other tag. The library's docs tell you what each tag takes: its attributes, slots, events, methods, and CSS parts.

A component library is a set of ready-made web components from one team. Ravi picks Web Awesome. It's free and open source, and it works on a plain HTML page. Here is his first try:

A first page with Web Awesome, from its CDNPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <h1>Leaf and Kettle</h1><wa-button variant="brand">Add to order</wa-button>
ResultLoading…
  • Line 1 loads Web Awesome's stylesheet from the internet. It holds the library's colors, fonts, and sizes.
  • Line 2 loads the library's loader, a small module script. When it finds a Web Awesome tag on the page, it loads the code for that tag.
  • Line 4 is a normal heading.
  • Line 5 is a tag from the library, <wa-button>. Its attribute variant="brand" asks for the theme's main color.

The result shows Leaf and Kettle and a blue Add to order button. Ravi wrote no class. He never called customElements.define(). The library did both, the way you did for tea-label in lesson 1.1. Every Web Awesome tag starts with wa-, so it can't clash with the kit's tea- tags.

Loading a library from a CDN. The page holds three lines: link, script, and wa-button. An arrow leads to the CDN, which holds webawesome.css, loader.js, and button.js. An arrow leads to the result: a page with the heading Leaf and Kettle and an Add to order button.your pagehtml<link><script><wa-button>the CDNCDNwebawesome.cssloader.jsbutton.jsthe resultpageLeaf and KettleAdd to order
The page asks the CDN for the stylesheet and the loader. The loader then fetches button.js, because the page uses <wa-button>. The result is a blue button.
Real-life analogyReady-made cups before pottery class

Leaf and Kettle needs cups for its new menu. Ravi could take a pottery class and make each cup by hand, but that would take months. So he buys a box of ready-made cups today. Later, once he can make cups himself, he'll make the special ones.

In real life: The shop that sells the cups
In JavaScript: Web Awesome, the library
In real life: Bringing the cups home
In JavaScript: The two lines that load the library
In real life: Pouring tea into a cup
In JavaScript: Writing <wa-button> in your page
In real life: The note that comes in the box
In JavaScript: The library's docs
In real life: The pottery class
In JavaScript: Stages 2 to 7, where you build your own tags
The main idea

A component library is a box of ready-made tags. Load its stylesheet and its loader, then write its tags in your HTML. Its docs tell you what each tag can do.

You may meet Web Awesome under an older name. Web Awesome is the next major version of a library called Shoelace. Shoelace is now sunset: nobody works on it anymore, and its last release was 2.20.1, on March 11, 2025. Its tutorials are still online. Their tags start with sl-, as in <sl-button>. In Web Awesome they start with wa-. Exercise 4 fixes one.

How do you load a component library from a CDN?

A CDN is a server that hosts files for many sites, as lesson 1.4 showed. Web Awesome runs its own. Its installation page gives you lines to paste into your page's <head>. Two are required: a theme stylesheet, styles/themes/default.css, and the loader. Two more stylesheets are optional. The page also offers one stylesheet that holds all three, styles/webawesome.css. The first page uses that one, plus the loader.

The version is part of the address

Here is the loader's address from line 2, split into its three parts:

The parts of the loader's addressText
https://ka-f.webawesome.com     the CDN's server
/webawesome@3.15.0              the package, and its version
/webawesome.loader.js           the file
  • Line 1 is the CDN's server.
  • Line 2 names the package, webawesome, and pins its version: 3.15.0.
  • Line 3 is the file.

The version in the address never changes by itself. When a newer Web Awesome comes out, your page still gets 3.15.0. You move up when you're ready, by changing the number in both lines. Why it matters: a new release can change how a tag looks or works. With a pinned address, nothing on your site changes until you choose.

Real-life analogyOrdering by item number

Leaf and Kettle orders its teapots from a supplier's list. The order form says "teapot, item 3150". Every order brings the same teapot, even after the supplier adds new ones. To try a new teapot, Ravi writes a new number on the form.

In real life: The supplier's warehouse
In JavaScript: The CDN
In real life: The item number on the order form
In JavaScript: The version in the address, @3.15.0
In real life: The order form
In JavaScript: The <link> and <script> lines
In real life: Writing a new number on the form
In JavaScript: Changing the version in both lines

Two lines, two jobs

The stylesheet holds the theme: the colors, fonts, spacing, and sizes that every component uses. This one stylesheet also gives plain HTML, like the heading, the library's look. And it adds a few layout classes.

The loader is the part that defines the tags. Leave one line out, and see what's left:

Playground: leave a line out
The first page, with one line or none left outPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <h1>Leaf and Kettle</h1><wa-button variant="brand">Add to order</wa-button>
ResultLoading…
Try it yourself
The result shows: A blue Add to order button

Line 1 brings the theme, and line 2 brings the loader. The loader defines wa-button, and the theme paints it blue with white text and round corners.

The page is the first example each time. A missing line becomes an HTML comment, so the other lines keep their numbers. Each choice runs in a fresh page.

Without the stylesheet, the button still works. It's defined, and you can click it. It just has no colors. Without the loader, wa-button is an unknown tag. The browser shows its text and waits, as lesson 1.1 explained. You need both lines.

Free and Pro components

Web Awesome's core is free, under the MIT license. Some components belong to Web Awesome Pro, a paid plan. The components page marks them with a Pro badge. They include the charts, the data grid, the combobox, the date picker, and the video player.

The npm package and the CDN address above hold only the free ones: 78 of them in version 3.15.0. This lesson uses five free components: the button, the badge, the rating, the card, and the dialog.

How does the autoloader load tags on demand?

Web Awesome has 78 free components, and the first page used one. Did the browser download all of them? No. The loader is an autoloader: it loads each component the first time the page needs it. That's what "on demand" means. Here is what it does, step by step:

  1. When it starts, it looks through the page for tags whose names start with wa- and that aren't defined yet.
  2. For each one, it builds an address from the tag's name. wa-button becomes components/button/button.js, in the folder the loader came from.
  3. It loads that file with dynamic import, import(), which loads a module while the page runs. The file defines the tag, and the browser upgrades every <wa-button> on the page.
  4. Then it keeps watching, with a MutationObserver: a browser feature that reports when elements are added to the page. A new wa- tag gets its file too.

Try step 4. This page has a button, and a click adds a star rating:

A rating that arrives on clickPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <wa-button>Rate this tea</wa-button><div id="rating-spot"></div> <script>  console.log(customElements.get("wa-rating"));  const button = document.querySelector("wa-button");  button.addEventListener("click", async () => {    document.querySelector("#rating-spot").innerHTML = '<wa-rating value="4"></wa-rating>';    await customElements.whenDefined("wa-rating");    console.log("wa-rating is ready");  });</script>
ResultLoading…
  • Line 4 is a button. Line 5 is an empty div, where the rating will go.
  • Line 8 asks the registry for wa-rating. Nothing uses that tag yet, so its file hasn't loaded. It prints undefined.
  • Lines 10 and 11 put <wa-rating value="4"> in the div when you click.
  • Line 12 waits until the tag is defined. customElements.whenDefined() gives back a promise: a value that will be ready later. await waits for it.
  • Line 13 prints wa-rating is ready.

Click Rate this tea. Four stars out of five appear, and the console prints wa-rating is ready. The loader saw the new tag and fetched its file. To watch it happen, open DevTools and click the Network tab. Type components in its filter box, then run the example again. Before the click, the list shows button.js. After it, rating.js joins it.

The autoloader at work. The page holds wa-button, and wa-rating added on click. An arrow leads to the autoloader. Arrows lead from it to two files on the CDN, button.js and rating.js. Two more files, dialog.js and card.js, are faded: nothing on the page uses them, so they never load.the pagepage<wa-button><wa-rating>added on clickthe autoloaderloaderon the CDNCDNbutton.jsrating.jsdialog.jscard.js
The loader finds <wa-button> at the start, and <wa-rating> when the click adds it. It loads those two files. Files for tags the page never uses stay on the CDN.
Real-life analogyA waiter who brings only what's ordered

In a busy café, a waiter walks between the tables. When a customer orders, the waiter brings that one dish from the kitchen. A customer who comes in later gets served too. The kitchen never sends out every dish on the menu.

In real life: The waiter walking between the tables
In JavaScript: The loader watching the page
In real life: An order on a table
In JavaScript: An undefined wa- tag
In real life: Fetching that dish from the kitchen
In JavaScript: Importing components/rating/rating.js
In real life: A customer who sits down later
In JavaScript: A tag added after the page loads
In real life: Dishes nobody ordered
In JavaScript: Component files that never load

Why it matters: a page that uses three components downloads those three, plus the shared code they need. You get the whole library with two lines, and the browser fetches only what you use.

Importing one component yourself

You can also skip the loader and import each component's file yourself. Each docs page has an Importing section with the line to use. People call this cherry-picking: choosing exactly the components you want.

Import the button's file, and nothing elsePop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module">  import "https://ka-f.webawesome.com/webawesome@3.15.0/components/button/button.js";</script> <wa-button variant="brand">Add to order</wa-button><wa-badge>New</wa-badge>
ResultLoading…
  • Line 1 loads the stylesheet, as before.
  • Lines 2 to 4 are a module script with one import: the button's file, copied from the Button docs.
  • Line 6 is a button. Line 7 is a badge, <wa-badge>: a small label for words like "New".

The result shows a blue button and the plain word New. Only the button's file was imported, so only wa-button is defined. The badge waits. The button's file also defined two tags the button uses inside it, wa-icon and wa-spinner. The Button docs list them under Dependencies.

The autoloader can't see inside shadow roots

The loader searches the page's own tree. It doesn't look inside shadow roots, the private trees from lesson 1.1. That matters as soon as your own components use library tags inside them. Switch between the two choices:

Playground: a button inside a shadow root
A wa-button inside your own shadow rootPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <tea-order></tea-order> <script>  class TeaOrder extends HTMLElement {    constructor() {      super();      const shadow = this.attachShadow({ mode: "open" });      shadow.innerHTML = "<wa-button>Order</wa-button>";    }  }   customElements.define("tea-order", TeaOrder);</script>
ResultLoading…
Try it yourself
The result shows: Order, as plain text

The loader looks for undefined wa- tags in the page's own tree. It can't see inside the shadow root that line 10 makes, so it never loads the button's file. Nothing else on the page uses wa-button, so the tag stays undefined.

Both choices use the same tea-order component, whose shadow root holds a wa-button. Only the second line changes: the autoloader, or an import of the button's file.

With the loader alone, Order stays plain text. The button sits in the shadow root of <tea-order>, where the loader never looks. Import the button's file instead, and the button appears. A definition is for the whole page, so it upgrades the button wherever it is.

If another <wa-button> were on the page, the loader would load the file for that one. The hidden button would then work too, but only by luck. So a component should import the library tags it uses inside its own file. Then it works on any page.

Read each row across: the question, then the answer for each way of loading.

The autoloader, or your own imports
What you want to knowWith the autoloaderImporting each file yourself
Which files load?Only the files for the wa- tags it finds, when it finds them.The files you import, and the files they import.
What about a tag added later?It sees the new tag and loads its file then.It works only if you imported its file.
What about a tag inside your own shadow root?It can't see the tag, so the tag stays undefined.It works. The import defines the tag for the whole page.
How much do you write?One script line for the whole library.One import line for each component.

How do you install a component library from npm?

The CDN is the quickest start. But Ravi's project from lesson 1.4 already uses npm and a dev server. With npm, the library's files live in his own project. His own server sends them, and the version is written in package.json. In the leaf-and-kettle folder, he runs:

Install Web Awesome into the projectShell
npm install @awesome.me/webawesome

npm downloads the package into the project. Here is what lands there, shortened:

The project after npm install (shortened)Text
leaf-and-kettle/
  index.html
  package.json        lists "@awesome.me/webawesome": "^3.15.0"
  node_modules/
    @awesome.me/webawesome/
      dist/           files for a bundler, such as Vite
      dist-cdn/       files ready for the browser, like the CDN's
        webawesome.loader.js
        styles/webawesome.css
        components/button/button.js
  • Line 3: package.json now lists the package. ^3.15.0 means "this version, or a newer one with the same first number". A second file, package-lock.json, records the exact version npm installed.
  • Line 6, dist/, is for projects with a bundler.
  • Line 7, dist-cdn/, holds files with everything bundled together, ready for the browser. They're the same files the CDN sends.
  • Lines 8 to 10 are the three files the first page used: the loader, the stylesheet, and the button.

So the npm version is the first page with new addresses. Here it is as a whole index.html, so the dev server can add its live reload:

The first page, loading Web Awesome from node_modulesHTML
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Leaf and Kettle</title>
    <link rel="stylesheet" href="/node_modules/@awesome.me/webawesome/dist-cdn/styles/webawesome.css">
    <script type="module" src="/node_modules/@awesome.me/webawesome/dist-cdn/webawesome.loader.js"></script>
  </head>
  <body>
    <h1>Leaf and Kettle</h1>
    <wa-button variant="brand">Add to order</wa-button>
  </body>
</html>
  • Lines 6 and 7 are the two lines from before. Each address now starts with /node_modules/, a folder in your project.
  • Lines 10 and 11 are the same heading and button.

Start the dev server with npm start, as in lesson 1.4, and open the page. It shows the same blue button. This time, nothing comes from Web Awesome's server.

Two places, the same files. A tag labelled CDN @3.15.0 and a tag labelled npm dist-cdn/ both point to one set of files: loader.js, styles, and components. An arrow leads from the files to the page, which shows Leaf and Kettle and an Add to order button.CDN@3.15.0a pinned addressnpmdist-cdn/your projectthe same filesfilesloader.jsstyles/components/the resultpageLeaf and KettleAdd to order
The CDN and the package's dist-cdn folder hold the same files. Only the address in the page's two lines changes.
Real-life analogyA tin of tea in your own pantry

Leaf and Kettle could buy its tea from the café next door, one pot at a time. Or it can buy a big tin and keep it in its own pantry. The tea is the same. But the tin is there even when the café is closed, and Ravi decides when to buy a new one.

In real life: The café next door
In JavaScript: The CDN
In real life: The tin in the shop's own pantry
In JavaScript: The package in node_modules
In real life: The date on the tin's label
In JavaScript: The version in package.json
In real life: Buying a new tin
In JavaScript: Installing a newer version with npm

The first slash matters

Notice that both addresses start with /. The loader works out where its component files are from its own src. It drops the file name and keeps the folder: /node_modules/@awesome.me/webawesome/dist-cdn. The docs call that folder the base path.

Without the first /, the folder becomes node_modules/@awesome.me/…. That looks like a bare name. As lesson 1.4 showed, a browser can't load a bare name on its own, so every component fails to load. Exercise 5 shows the warning Chrome prints.

Some projects put the loader inside a file of their own. Then its src no longer points at the library's folder. The installation page's "Setting the base path" section shows the fix: name the folder in a data-webawesome attribute on your script.

With a bundler

Many projects use a bundler: a tool, like Vite, that joins your files into fewer files before the browser sees them. Then you import from dist, by the package's name, as the installation page shows:

Web Awesome in a project with a bundlerJavaScript
// In a project with a bundler, such as Vite
import "@awesome.me/webawesome/dist/styles/webawesome.css";
import "@awesome.me/webawesome/dist/components/button/button.js";

Line 1 is a comment. Line 2 brings in the stylesheet, and line 3 brings in the button. These are bare names, so the bundler has to turn them into real files. This course doesn't use a bundler, so it uses dist-cdn.

Read each row across: the question, then the answer for the CDN and for npm.

The CDN or npm
What you want to knowFrom the CDNFrom npm
Where do the files come from?Web Awesome's server, ka-f.webawesome.com.Your project's own node_modules folder.
Where is the version written?In the address: webawesome@3.15.0.In package.json, and exactly in package-lock.json.
What do you need first?Nothing. Paste two lines into a page.Node.js, npm, and a dev server, as in lesson 1.4.
Who sends the files to visitors?Web Awesome's CDN.Your own server, the one that sends your pages.

How do you read a web component's docs?

Ravi has a button on his page. Now he wants a smaller one, a round one, and one with a price on it. The answers are in the docs. Every Web Awesome component has its own page. Each page ends with a set of tables, under the heading API. They list the tag's public parts: the ones you're meant to use.

Real-life analogyThe manual that comes with a kettle

A new kettle comes with a small manual. One page lists the settings, like the water's heat. One shows the sockets on the back. One says what each beep means, and one shows the buttons. You don't need to know how the kettle works inside. You read the page that answers your question.

In real life: The settings you can pick
In JavaScript: Attributes and properties
In real life: The sockets you plug things into
In JavaScript: Slots
In real life: The beep when the water boils
In JavaScript: Events
In real life: The buttons you press
In JavaScript: Methods
In real life: The parts you may paint
In JavaScript: CSS parts

Open the Button docs and scroll down to API. This picture shows what each table describes:

The parts of a wa-button that its docs describe. The button holds three pieces: a plus sign in the start slot, Add to order in the default slot, and 4.00 in the end slot. An attribute, variant equals brand, points into it. A method, focus(), points into it. An event, focus, comes out of it. A CSS part, ::part(button), points at its outer edge.attributevariant="brand"eventfocusmethodfocus()CSS part::part(button)+Add to order4.00start(default)endslots
Each table in the docs describes one way in or out of the tag. Attributes and methods go in. Events come out. Slots take your content, and parts let your CSS reach inside.

Attributes and properties

This is the longest table. Each row is one setting. The first column shows two names. On top is the property name, which you use in JavaScript. Under it is the attribute name, which you write in HTML. They're often the same, like variant. Sometimes they differ: the property withCaret is the attribute with-caret.

Each row also gives a type, often a default, and whether it reflects. A setting that reflects keeps the attribute in step with the property: change one, and the other follows. Try five rows of the table, one at a time:

Playground: try a row of the table
One attribute from the Button docsPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <wa-button variant="brand">Add to order</wa-button>
ResultLoading…
Try it yourself
Line 4 sets variant="brand"

The row for variant lists five values: neutral, brand, success, warning, and danger. Its default is neutral, a dark gray. brand paints the button in the theme's main color, blue.

Each button puts one attribute from the Button docs on line 4. Press Edit & run to combine two, like a large brand button.

Now read the type row carefully. Its default is button. A plain <button> defaults to submit, so inside a form it sends the form. A <wa-button> doesn't, unless you write type="submit". Web Awesome's usage guide warns about this: don't assume a library tag works like the HTML tag it looks like. Exercise 2 tests it.

Slots

The Slots table lists the places in the tag where your own content goes. A button has three. The default slot takes everything without a slot attribute: here, the label. The start and end slots each take an element, placed before or after the label:

Content in a button's three slotsPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <wa-button variant="brand">  <span slot="start">+</span>  Add to order  <span slot="end">4.00</span></wa-button>
ResultLoading…
  • Line 5 sends a + sign to the start slot.
  • Line 6 has no slot attribute, so it goes to the default slot.
  • Line 7 sends the price to the end slot.

The result shows +, then Add to order, then 4.00, all on one button. These are the slots from lesson 1.1. The button's shadow root has three <slot> elements, and the browser shows your content in them.

Events and methods

The Events table lists what the tag announces. A button has three: focus, blur, and wa-invalid. Web Awesome's own events start with wa-, so they can't clash with the browser's events. The Methods table lists what you can ask the tag to do, such as focus(), blur(), and click().

Listen for two events from the tablePop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <wa-button>Add to order</wa-button> <script>  const button = document.querySelector("wa-button");  button.addEventListener("focus", () => console.log("focus"));  button.addEventListener("blur", () => console.log("blur"));</script>
ResultLoading…
  • Line 7 finds the button.
  • Lines 8 and 9 listen for two events from the table, focus and blur. Each one prints its name.

Click an empty part of the result, then press Tab. Focus moves to the button, and the console prints focus. Press Tab again, and it prints blur. The next lesson calls methods and sets properties from JavaScript.

Custom states and CSS parts

The last two tables are about styling. A CSS part is an element inside the shadow root that the component lets you style from outside, with ::part(). A custom state is a name the component turns on and off, like disabled. Your CSS can match it with :state().

Style two parts and a state from your own CSSPop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <style>  wa-button::part(button) { border-radius: 0; }  wa-button::part(label) { text-transform: uppercase; }  wa-button:state(disabled) { outline: 2px dashed gray; }</style> <wa-button variant="brand">Add to order</wa-button><wa-button disabled>Sold out</wa-button>
ResultLoading…
  • Line 5 styles the button part, the button's outer wrapper. It squares the corners.
  • Line 6 styles the label part. It turns the text into capitals.
  • Line 7 matches any wa-button in the disabled state, and draws a dashed line around it.
  • Lines 10 and 11 are two buttons. The second one is disabled.

The result shows ADD TO ORDER with square corners, and a faded SOLD OUT with a dashed outline. You styled the inside of a shadow root, but only where the component allows it. Lesson 2.3 covers theming from the outside in full.

Where the facts in the tables live

The same facts sit in a file inside the package, dist/custom-elements.json. It's a custom elements manifest: one JSON file that lists every tag a package defines, with its attributes, slots, events, CSS parts, and more. Here is a shortened piece of the entry for wa-button:

Part of wa-button's entry in custom-elements.json (shortened)JSON
{
  "tagName": "wa-button",
  "attributes": [
    { "name": "variant", "default": "'neutral'" },
    { "name": "size", "default": "'m'" }
  ],
  "slots": [{ "name": "" }, { "name": "start" }, { "name": "end" }],
  "events": [{ "name": "blur" }, { "name": "focus" }, { "name": "wa-invalid" }],
  "cssParts": [{ "name": "button" }, { "name": "label" }],
  "cssStates": [{ "name": "disabled" }, { "name": "loading" }]
}
  • Line 2 names the tag.
  • Lines 3 to 6 list two attributes and their defaults, neutral and m, as the docs say.
  • Line 7 lists the slots. The empty name, "", is the default slot.
  • Lines 8 to 10 list the events, two of the CSS parts, and two of the custom states.

The format is shared. It was written so that editors, docs sites, and other tools can read the same kind of file, whatever library made it. A package points to its manifest with a customElements field in its package.json, and Web Awesome's does. Code editors can read it to suggest tags and attributes as you type, and docs sites can show it as tables. When you choose a library, check that it ships one.

Now sort each task by the table that answers it:

Which table answers it?
  • Make the button blue
  • Make the button larger
  • Let the button send a form
  • Show a price after the label
  • Put a + before the label
  • Run code when the button gets focus
  • Square the button's corners from your CSS
  • Turn the label into capitals from your CSS
Try it yourself
0 of 8 correct

Sort each task for wa-button by the table in its docs that tells you how.

Choose a category for every card. You can change an answer at any time; Reset clears them all.

Build a first page with Web Awesome

Ravi now has what he needs for the menu page. He read three docs pages: Card, Button, and Dialog. Every line below comes from a row in one of their tables:

Leaf and Kettle's menu page, built from Web AwesomePop out in the code editor (opens in a new tab)HTML
<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <h1>Today's teas</h1><div class="wa-grid">  <wa-card>    <strong slot="header">Green tea</strong>    Brew for 3 minutes. Price: 4    <wa-button slot="footer" variant="brand" data-dialog="open thanks">Add to order</wa-button>  </wa-card>  <wa-card>    <strong slot="header">Black tea</strong>    Brew for 4 minutes. Price: 5    <wa-button slot="footer" variant="brand" data-dialog="open thanks">Add to order</wa-button>  </wa-card></div> <wa-dialog id="thanks" label="Thank you">  Your tea is on its way to the counter.  <wa-button slot="footer" data-dialog="close">Close</wa-button></wa-dialog>
ResultLoading…
  • Line 4 is the page's heading. Line 5 lays the cards out in a grid, with the wa-grid class from the stylesheet.
  • Lines 6 to 10 are one card. The Card docs list a header slot and a footer slot. Line 7 puts the tea's name in the header, and line 9 puts the button in the footer.
  • Line 9 also has data-dialog="open thanks". The Dialog docs say this attribute, on any button, opens the dialog whose id is thanks.
  • Lines 11 to 15 are the second card, for black tea.
  • Lines 18 to 21 are the dialog. label is its title. On line 20, data-dialog="close" closes it.

Click Add to order on either card. The dialog opens over the page, with the title Thank you. Press Close, or the Escape key, and it closes. Ravi wrote no JavaScript for any of it.

Why it matters: the dialog is built on the browser's own <dialog> element. When it opens, focus moves into it. Building one well yourself means taking care of focus, the keyboard, and screen readers. Stage 5 covers those. Later in this course, you'll swap some of these pieces for your own tea kit components, one at a time. The page keeps working, because every piece is an HTML tag.

Before you pick a library

A library becomes part of your site, so check that someone still looks after it. Look for:

  • recent releases on npm, and a code repository that isn't archived;
  • a clear line between the free parts and the paid ones;
  • docs with API tables for every tag, and a custom elements manifest in the package;
  • a way to pin the version, so updates happen when you choose.

Two well-known libraries fail the first check. Shoelace is sunset, and its repository is archived. Google's Material Web is still on npm. But in June 2024 its team put it in maintenance mode: no new features or components are planned. So before you copy a tutorial, check the library behind it, as lesson 1.2 did for old browser APIs.

Common mix-ups

  • "A component library is a framework, and your app must be built in it." No. Each wa- tag is a custom element. It works on a plain HTML page, and in frameworks too.
  • "The loader downloads the whole library." No. It loads the files for the wa- tags it finds on the page, when it finds them.
  • "The autoloader finds every wa- tag, even inside shadow roots." No. It only searches the page's own tree. Import the files for tags you put inside your own shadow roots.
  • "Without the stylesheet, the tags don't work." No. They work, but with no colors, fonts, or sizes. Load both lines.
  • "<wa-button> works just like <button>." No. Its type defaults to button, so it doesn't send a form. Read the docs before you assume.
  • "Shoelace tutorials work if you load Web Awesome." No. Tags change from sl- to wa-, and some values change too, like variant="primary" to variant="brand".
  • "Every Web Awesome component is free." No. The charts, the data grid, the combobox, the date picker, and a few more are Pro. The npm package has only the free ones.

Practice exercises

Answer first, then use the hints. Most results run live, so you can check yourself.

Exercise 1 · Warm-upWhich file loads?

This page uses one tag from the library. Which file does the autoloader fetch for it?

<link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <wa-badge>New</wa-badge>
ResultLoading…

Answer, then press Check. Spacing and letter case don’t matter.

    Exercise 2 · Warm-upDoes it send the form?

    Click Send order. What does the paragraph say now?

    <link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <form>  <wa-button>Send order</wa-button></form><p>Not sent</p> <script>  const form = document.querySelector("form");  form.addEventListener("submit", (event) => {    event.preventDefault();    document.querySelector("p").textContent = "Sent";  });</script>
    ResultLoading…

    Answer, then press Check. Spacing and letter case don’t matter.

      Exercise 3 · PracticeFill the card's slots

      Everything in this card sits in its body. Use the Card docs to put the tea's name in the header and the button in the footer. Which attribute did you add to both?

      <link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <wa-card>  <strong>Mint tea</strong>  Brew for 5 minutes.  <wa-button variant="brand">Add to order</wa-button></wa-card>
      ResultLoading…

      Answer, then press Check. Spacing and letter case don’t matter.

        Exercise 4 · PracticeA line from a Shoelace tutorial

        Ravi copied line 4 from an old Shoelace tutorial, and it shows plain text. Fix it. What does the tag's name start with now?

        <link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <sl-button variant="primary">Add to order</sl-button>
        ResultLoading…

        Answer, then press Check. Spacing and letter case don’t matter.

          Exercise 5 · ChallengeThe missing character

          Ravi's npm page shows the theme's fonts, but the button stays plain text. Chrome's console warns: Unable to autoload <wa-button> from node_modules/@awesome.me/webawesome/dist-cdn/components/button/button.js. Which one character is missing at the start of both paths?

          Starter codeHTML
          <link rel="stylesheet" href="node_modules/@awesome.me/webawesome/dist-cdn/styles/webawesome.css">
          <script type="module" src="node_modules/@awesome.me/webawesome/dist-cdn/webawesome.loader.js"></script>
          
          <wa-button variant="brand">Add to order</wa-button>

          Answer, then press Check. Spacing and letter case don’t matter.

            Exercise 6 · ChallengeRead the Dialog docs

            Open the dialog, then click outside it. It stays open. Find the attribute in the Dialog docs that closes it when you click outside, and add it to line 4. Which attribute is it?

            <link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css"><script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script> <wa-dialog id="brew" label="How to brew">  Use water at 80 degrees. Brew for 3 minutes.</wa-dialog><wa-button data-dialog="open brew">How to brew</wa-button>
            ResultLoading…

            Answer, then press Check. Spacing and letter case don’t matter.

              Check your understanding

              For each question, think about the three parts: the stylesheet, the loader, and the docs.

              The component library quiz · 8 questionsScore: first tries count
              1. Question 1 of 8What do the two lines from the CDN snippet load?

                Choose an answer to see the explanation.

              2. Question 2 of 8A page loads the autoloader but leaves out the stylesheet. What does its <wa-button variant="brand"> show?

                Choose an answer to see the explanation.

              3. Question 3 of 8In the rate-this-tea example, what does the console print first, before any click?

                Read the code, then predictPop out in the code editor (opens in a new tab)HTML
                <link rel="stylesheet" href="https://ka-f.webawesome.com/webawesome@3.15.0/styles/webawesome.css">
                <script type="module" src="https://ka-f.webawesome.com/webawesome@3.15.0/webawesome.loader.js"></script>
                
                <wa-button>Rate this tea</wa-button>
                <div id="rating-spot"></div>
                
                <script>
                  console.log(customElements.get("wa-rating"));
                  const button = document.querySelector("wa-button");
                  button.addEventListener("click", async () => {
                    document.querySelector("#rating-spot").innerHTML = '<wa-rating value="4"></wa-rating>';
                    await customElements.whenDefined("wa-rating");
                    console.log("wa-rating is ready");
                  });
                </script>

                Choose an answer to see the explanation.

              4. Question 4 of 8Which file does the autoloader import when it finds <wa-rating>?

                Choose an answer to see the explanation.

              5. Question 5 of 8Your own component puts <wa-button> in its shadow root. Nothing else on the page uses it, and the page has only the autoloader. What happens?

                Choose an answer to see the explanation.

              6. Question 6 of 8Why does the CDN address have @3.15.0 in it?

                Choose an answer to see the explanation.

              7. Question 7 of 8In the Button docs, which table tells you how to square the button's corners from your own CSS?

                Choose an answer to see the explanation.

              8. Question 8 of 8What happened to the Shoelace library?

                Choose an answer to see the explanation.

              Key takeaways

              • A component library is a set of ready-made tags. Load its stylesheet and its loader, then write its tags.
              • From the CDN, it's two lines with a pinned version. From npm, it's the same files in node_modules/@awesome.me/webawesome/dist-cdn, with addresses that start with /.
              • The autoloader finds undefined wa- tags, now and later, and imports components/<name>/<name>.js for each. It can't see inside shadow roots.
              • Import a component's file yourself when you want only that one, or when your own shadow root uses it.
              • A docs page's API tables list attributes and properties, slots, events, methods, custom states, and CSS parts. A custom elements manifest holds the same facts.
              • Read before you assume: <wa-button> sends no form without type="submit", and Shoelace tutorials need sl- changed to wa-.

              Remember the one-liner.
              Load the library's stylesheet and loader, write its tags, and let its docs tell you what each tag takes.

              Sources

              The facts on this page come from these docs, specifications, and posts:

              Coming next: Talking to a component from JavaScript. Set properties, call methods, and listen for events on someone else's component.

              CompleteFrontend Clear concepts. Working examples.