npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-html-elements

v0.0.9

Published

Modular HTML without the JavaScript

Downloads

7

Readme

💧 vite-plugin-html-elements

Modular HTML without the JavaScript

A lightweight Vite plugin for composing reusable HTML elements in static sites. Keep your HTML DRY and maintainable without adding runtime JavaScript.

✨ Features

  • Zero JavaScript - Pure static HTML output
  • Hot Reload - Instant updates during development
  • Intuitive Syntax - Natural self-closing <element /> tags
  • Shorthand Support - <element src="header.html" />
  • TypeScript - Full type safety
  • Tiny - Minimal footprint, maximum impact

📦 Installation

npm install -D vite-plugin-html-elements

🚀 Quick Start

1. Add to your Vite config

// vite.config.js
import { defineConfig } from 'vite';
import { htmlElements } from 'vite-plugin-html-elements';

export default defineConfig({
  plugins: [htmlElements()],
});

2. Create your project structure

project/
├── src/
│   ├── elements/
│   │   ├── header.html
│   │   └── footer.html
│   └── index.html
└── vite.config.js

3. Create reusable elements

src/elements/header.html:

<header>
  <nav>
    <a href="/">Home</a>
    <a href="/about">About</a>
    <a href="/contact">Contact</a>
  </nav>
</header>

4. Use elements in your pages

src/index.html:

<!doctype html>
<html lang="en">
  <head>
    <title>My Site</title>
    <link rel="stylesheet" href="/styles.css" />
  </head>
  <body>
    <element src="header.html" />

    <main>
      <h1>Welcome to my site!</h1>
    </main>

    <element src="footer.html" />
  </body>
</html>

5. Build

npm run dev    # Development with hot reload
npm run build  # Production build

The output is pure static HTML with all elements inlined - no <element> tags remain.

📝 Syntax

Shorthand (Recommended)

<element src="header.html" />

Automatically resolves to elements/header.html

Explicit Paths

<element src="elements/nav/mobile.html" />

⚙️ Configuration

Debug Mode

Enable verbose logging to see which elements are being included:

htmlElements({ debug: true });

Output:

💧 Element included: elements/header.html
💧 Element included: elements/footer.html

📁 Project Structure

Organize your project however you prefer. Here are some common patterns:

Simple Structure

project/
├── src/
│   ├── elements/
│   │   ├── header.html
│   │   └── footer.html
│   ├── index.html
│   └── about.html
└── vite.config.js

Organized Structure

project/
├── src/
│   ├── elements/
│   │   ├── head.html
│   │   ├── header.html
│   │   ├── footer.html
│   │   └── nav/
│   │       ├── mobile.html
│   │       └── desktop.html
│   ├── index.html
│   ├── about.html
│   └── styles.css
├── public/
│   └── favicon.ico
└── vite.config.js

🎯 Use Cases

Perfect for:

  • 📄 Landing pages
  • 📝 Documentation sites
  • 📰 Blogs
  • 🎨 Marketing sites
  • 🏢 Company websites
  • 🚀 Any multi-page static site

Ideal when you want:

  • Reusable HTML components
  • No build complexity
  • Progressive enhancement
  • Fast, accessible sites
  • SEO-friendly output

💡 Philosophy

HTML and CSS are powerful. JavaScript is optional.

This plugin embraces the web platform by making static HTML modular and maintainable without introducing runtime dependencies or complex tooling.

Start with solid HTML, add CSS for style, and layer JavaScript only where it adds value.

📚 Examples

Shared Head Element

src/elements/head.html:

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="stylesheet" href="/styles.css" />
  <link rel="icon" href="/favicon.ico" />
</head>

src/index.html:

<!doctype html>
<html lang="en">
  <element src="head.html" />
  <body>
    <!-- content -->
  </body>
</html>

Component Library

elements/
├── buttons/
│   ├── primary.html
│   └── secondary.html
├── cards/
│   ├── product.html
│   └── blog.html
└── layouts/
    ├── header.html
    └── footer.html
<element src="buttons/primary.html" /> <element src="cards/product.html" />

❓ FAQ

Can I use relative paths?
Yes! Paths are resolved relative to the HTML file containing the <element /> tag.

Does it work with other Vite plugins?
Yes! Fully compatible with Tailwind CSS and other Vite plugins.

Can elements include JavaScript?
Elements are just HTML. You can include <script> tags in your elements if needed.

What about dynamic content?
This plugin is for static composition at build time. For dynamic content, layer on JavaScript after your HTML is built.

Do I need Node.js at runtime?
No! The plugin runs at build time. The output is pure static HTML that works anywhere.

🤝 Contributing

Contributions welcome! Please open an issue or PR on GitHub.

📄 License

MIT

🔗 Links