--- layout: layouts/page.njk title: Installation description: How to install and use Basecoat in your app. toc: - label: Install using the CDN id: install-cdn children: - label: Install all components id: install-cdn-all - label: Install specific components id: install-cdn-specific - label: Installing using NPM id: install-npm children: - label: Add Tailwind CSS id: install-npm-tailwind - label: Add Basecoat id: install-npm-basecoat - label: Import basecoat in your CSS id: install-npm-import - label: (Optional) Add JavaScript files id: install-npm-js - label: That's it id: install-npm-done - label: Components with JavaScript id: install-js - label: Use the CLI id: install-cli - label: Use Nunjucks or Jinja macros id: install-macros - label: Theming id: install-theming --- {% from "macros/code_block.njk" import code_block %} {% from "tabs.njk" import tabs %}

Install using the CDN

Install all components

Add the following to the <head> of your HTML file:

{% set code %} {% endset %} {{ code_block(code, "html") }}

Install specific components

While the JavaScript file for all components is small (around 3kB gzipped), you can cherry-pick the components you need as instructed in the component's page (Dropdown Menu, Popover, Select, Sidebar, Tabs and Toast). For example, to add the Dropdown Menu component, add the following to the <head> of your HTML file:

{% set code %} {% endset %} {{ code_block(code, "html") }}

Install using NPM

  1. Add Tailwind CSS

    Basecoat uses Tailwind CSS. You need to install it in your project.

    Follow the Tailwind CSS installation instructions to get started.

  2. Add Basecoat

    Add Basecoat to your Tailwind CSS file.

    {% set code_npm %}npm install basecoat-css{% endset %} {% set code_pnpm %}pnpm add basecoat-css{% endset %} {% set code_bun %}bun add basecoat-css{% endset %} {% set code_yarn %}yarn add basecoat-css{% endset %} {% set tabsets = [ { tab: "npm", panel: code_block(code_npm, class="") }, { tab: "pnpm", panel: code_block(code_pnpm, class="") }, { tab: "bun", panel: code_block(code_bun, class="") }, { tab: "yarn", panel: code_block(code_yarn, class="") } ] %} {{ tabs(id="npm-install", tabsets=tabsets) }}

    Alternatively, you can directly copy the basecoat.css file into your project.

  3. Import basecoat in your CSS

    {% set code %}@import "tailwindcss"; @import "basecoat-css";{% endset %} {{ code_block(code, "css") }}
  4. (Optional) Add JavaScript files

    Some components need some JavaScript (e.g. the Tabs component). There are two ways to get it into your project:

    Using a build tool (Vite, Webpack…)

    If your project is ESM-aware you can directly import the scripts. To include all components:

    {% set code %}{% raw %}import 'basecoat-css/all';{% endraw %}{% endset %} {{ code_block(code, "js") }}

    Or cherry-pick specific components, for example:

    {% set code %}{% raw %}import 'basecoat-css/popover'; import 'basecoat-css/tabs';{% endraw %}{% endset %} {{ code_block(code, "js") }}

    Without a build tool

    Copy the pre-built files from node_modules into your public directory:

    {% set code %}npx copyfiles -u 1 "node_modules/basecoat-css/dist/js/**/*" public/js/basecoat{% endset %} {{ code_block(code, "bash") }}

    Then reference the script you need as well as the basecoat.min.js file (used to register and initialize components):

    {% set code %} {% endset %} {{ code_block(code, "html") }}

    See each component page for the minimal script required.

  5. That's it

    You can now use any of the Basecoat classes in your project (e.g. btn, card, input, etc). Read the documentation about each component to get started (e.g. button, card, input, etc).

    Some components (e.g. Select) require JavaScript code to work.

Components with JavaScript

A handful of components require JavaScript code to work., specifically Dropdown Menu, Popover, Select, Sidebar, Tabs and Toast

If a component requires JavaScript, the documentation page will provide instructions. There are 2 options to add the JavaScript code to your project:

Use the CLI

If you're using Nunjucks or Jinja, you can use the CLI to install the CSS and macros for any of the complex components(e.g. Dialog). It will copy the JS and .html.jinja or .njk macros into your code.

For example, to add the Dialog component, run one of the following commands:

{% set code_npm_exec %}npx basecoat-cli add dialog{% endset %} {% set code_pnpm_exec %}pnpm dlx basecoat-cli add dialog{% endset %} {% set code_bun_exec %}bunx basecoat-cli add dialog{% endset %} {% set code_yarn_exec %}yarn dlx basecoat-cli add dialog{% endset %} {% set exec_tabsets = [ { tab: "npm", panel: code_block(code_npm_exec, class="") }, { tab: "pnpm", panel: code_block(code_pnpm_exec, class="") }, { tab: "bun", panel: code_block(code_bun_exec, class="") }, { tab: "yarn", panel: code_block(code_yarn_exec, class="") } ] %} {{ tabs(id="cli-execution", tabsets=exec_tabsets, label="Execute CLI commands to add components:") }}

You will be asked to confirm the template engine and destination directory for the JavaScript and macros.

Use Nunjucks or Jinja macros

For more complex components, you can use Nunjucks or Jinja macros to help you generate the HTML and JavaScript code.

To install them, either copy them directly from the GitHub repository or use the CLI to do the work for you.

For example, here's how you could use the select() macro to generate the HTML and JavaScript code for a Select component:

{% set code %}{% raw %}{% call select() %}
Fruits
Apple
Banana
Blueberry
Grapes
Pineapple
{% endcall %}{% endraw %}{% endset %} {{ code_block(code, "jinja") }}

Theming

You can import any shadcn/ui compatible theme (e.g. tweakcn). For example:

About shadcn/ui theming {% lucide "arrow-right" %}

Customization

You can override default styles using Tailwind:

{% set code %}{% endset %} {{ code_block(code, "html") }}

You can also extend or override the existing styles in your own Tailwind files:

{% set code %}@import "tailwindcss"; @import "basecoat-css"; @import "./custom.css";{% endset %} {{ code_block(code, "css") }}

More importantly, you can use the theme variables to customize many aspects of the components (colors, fonts, sizes, etc).

If you want to make more drastic changes, you can copy the basecoat.css file into your project and make your changes there.