Custom components
You can extend DocsLit with your own Lit web components. Place a .js file in the components/ directory and it loads automatically alongside the built-in components.
Create a custom component
Create a file in components/ with your component definition:
Reference the component in any page — no imports needed:
docslit dev. The dev server loads custom components from components/ automatically and hot-reloads when you change them.
Component guidelines
LitElement, html, and css available globally. You do not need to import them in your component files.
Follow these conventions for custom components:
- Prefix with
wc-— All component tag names must start withwc-to work with the DocsLit rendering pipeline. - Use
LitElement— ExtendLitElementfor shadow DOM encapsulation and reactive properties. - Register with
customElements.define— Always define your element at the bottom of the file. - Keep components self-contained — Include styles within the component using
static styles.
File structure
Each .js file can contain one or more component definitions. DocsLit concatenates all files in components/ into a single script and loads it after the built-in components.
Validation
The docslit validate command knows about custom components. It scans components/ for customElements.define calls and treats those tags as valid. Any <wc-*> tag that is not built-in or defined in components/ triggers a warning.
Build output
Custom components are included in both static and offline builds automatically. The components/ directory is copied to dist/components/ during the build.