---
title: "Eleventy WebC guide: single-file components, props, slots, and gotchas"
description: "A practical guide to WebC in Eleventy for marketing sites: setting up the plugin, writing single-file components, props, loops, slots, server-only comments, and the gotchas that trip people up."
url: "https://mikestilling.com/guides/eleventy-webc-components/"
date: "2026-12-03"
author: "Mike Stilling"
---

> AI-generated from Mike Stilling's work, notes, and writing.

# Eleventy WebC

Mike Stilling's studio, Stilling, ran 5+ production marketing sites off one Eleventy boilerplate, and this site uses the same approach. The core of it is WebC: Eleventy's single-file component format. This guide covers how to set it up and write components, plus the gotchas that cost the most time.

It's part one of a two-part series. Part two covers [Eleventy, Tailwind, and Vite](https://mikestilling.com/guides/eleventy-tailwind-vite-setup/).

## The short answer

**WebC lets you write components as plain HTML files and use them like custom elements.** A file called `audio-player.webc` becomes an `<audio-player>` tag you can drop into any page. Eleventy renders it to static HTML at build time, so you get component-based authoring with no client-side framework.

## Why WebC for marketing sites

Marketing sites are mostly static pages with a lot of repeated parts: headers, cards, logo walls, CTAs, case study blocks. Components keep those consistent. Heavy JavaScript frameworks are usually overkill for that.

WebC hits a sweet spot:

- **Components are HTML.** Designers who know HTML and CSS can read and change them. There's no JSX and no framework syntax to learn first.
- **No runtime by default.** Output is plain HTML and CSS. JavaScript only ships where you add it on purpose.
- **Few dependencies.** Eleventy plus a plugin. Less to update, less to break.
- **Friendly to AI tools.** One component per file, with markup and logic together, means an agent like Claude Code can understand a component by reading one file. That turned out to matter a lot.

## Setup

Install Eleventy and the WebC plugin:

```bash
npm install @11ty/eleventy @11ty/eleventy-plugin-webc
```

Then register the plugin in your Eleventy config, and tell it where your components live:

```js
// eleventy.config.js
import pluginWebc from "@11ty/eleventy-plugin-webc";

export default function (eleventyConfig) {
    eleventyConfig.addPlugin(pluginWebc, {
        components: "src/_components/**/*.webc",
    });

    return {
        htmlTemplateEngine: "webc",
        dir: { input: "src", output: "dist", includes: "_components", layouts: "_layouts" },
    };
}
```

The `components` glob registers every `.webc` file in that folder globally, so you never import components by hand. Setting `htmlTemplateEngine` to `webc` lets you use components inside Markdown and HTML pages too.

## Your first component

A component is a `.webc` file. Its file name becomes its tag name:

```html
<!-- src/_components/cta-card.webc -->
<div class="rounded-8 p-24 bg-l2" webc:root="override">
    <h3 @text="title"></h3>
    <p><slot></slot></p>
    <a :href="href" @text="label"></a>
</div>
```

And using it on a page:

```html
<cta-card title="Talk to sales" href="/contact/" label="Get in touch">
    See how teams like yours use the product.
</cta-card>
```

A few things to notice:

- **`webc:root="override"`** replaces the `<cta-card>` tag with the component's root element, so you don't end up with an unknown custom element wrapping your `<div>`.
- **`@text`** sets an element's text from a prop or expression, escaped safely. `@html` does the same without escaping, so only use it for content you trust.
- **`<slot>`** is where the child content goes, like in web components.

## Props, loops, and conditions

Attributes are props. A plain attribute passes a string. Prefix it with a colon to pass a JavaScript expression:

```html
<audio-player :src="audio"></audio-player>
```

Here `audio` comes from the page's front matter. Inside the component, `:src="src"` puts that value on the real `<audio>` element.

Loops and conditions are attributes too:

```html
<ul webc:if="$data.related">
    <li webc:for="href of $data.related">
        <a :href="href" @text="href"></a>
    </li>
</ul>
```

`$data` holds the page's data: front matter plus anything from your data files. `webc:for` repeats an element per item, and `webc:if` renders it only when the expression is truthy. Add `webc:nokeep` to an element when you want its children rendered without the element itself. That's handy for wrappers that exist only to hold a loop.

## Pages as single files

Mike's boilerplate keeps each page as one file: the front matter (title, SEO description, social image), the content, and the markup together. Layouts handle the shared shell. Pages are made from components.

That structure pays off in three ways:

1. **Everything about a page is in one place.** Change a headline, its meta description, and its layout without hunting across folders.
2. **New pages are copies.** Duplicate a similar page and edit it. It's the fastest way to build, for people and AI tools alike.
3. **Search data stays honest.** When the SEO title sits next to the H1, they don't drift apart.

## Gotchas

- **Components in Markdown need their own line.** Put the opening tag on its own line with a blank line before it. Otherwise the Markdown parser may wrap it in a `<p>` and the output breaks.
- **Use server-only comments for notes.** ``, with three dashes, is stripped from the output. Regular `` comments ship to the browser.
- **Prefixes matter.** `href="url"` passes the literal text "url". `:href="url"` passes the value of `url`. When a link renders as a variable name, a missing colon is usually why.
- **Name components with a hyphen.** Custom element names need one (`cta-card`, not `ctacard`), and it keeps them from clashing with real HTML tags.
- **Restart after adding components.** If a brand-new component doesn't render, restart the dev server so the glob picks it up.
- **Keep scripts deliberate.** If a component needs client-side behavior, keep it small and colocated with the component, so it only loads where it's used.

Next up: [setting up Tailwind and Vite with Eleventy](https://mikestilling.com/guides/eleventy-tailwind-vite-setup/), including the build step that trips everyone up.

## Frequently asked questions

### What is WebC in Eleventy?

WebC is Eleventy's component language. A component is a single .webc file of plain HTML, with optional CSS and JavaScript, that you use like a custom element. At build time Eleventy renders it to static HTML, so nothing ships to the browser unless you choose to.

### Does WebC require JavaScript in the browser?

No. WebC components render on the server at build time. A component only ships client-side JavaScript if it includes a script you keep. A page built entirely from WebC components can be pure HTML and CSS.

### How do you pass props to a WebC component?

Use attributes. A static attribute like title="Pricing" passes a string. Prefix it with a colon, like :src="audio", to pass the result of a JavaScript expression, such as a value from front matter. Inside the component, you read them by name.

### Is WebC better than Nunjucks?

For component-heavy marketing sites, WebC is usually nicer: components are just HTML files, props look like attributes, and markup stays readable. Nunjucks is more mature and better documented, and it's a fine choice for template-heavy sites. You can use both in the same Eleventy project.

### Can I use WebC components inside Markdown?

Yes, if your Markdown is processed with WebC as the HTML template engine. Put the component's opening tag on its own line, with a blank line before it, so the Markdown parser treats it as an HTML block instead of wrapping it in a paragraph.
