Tailwind CSS

Integrate Turbo Themes with Tailwind CSS using the official preset.

Tailwind CSS Integration

Use Turbo Themes with Tailwind CSS for utility-first theming.

Installation

1. Install Packages

npm install @lgtm-hq/turbo-themes tailwindcss
# or
bun add @lgtm-hq/turbo-themes tailwindcss

2. Configure Tailwind

Use the Turbo Themes preset in your tailwind.config.js:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
  presets: [require('@lgtm-hq/turbo-themes/adapters/tailwind/preset')],
};

3. Include Theme CSS

Add the theme CSS to your HTML:

<link
  rel="stylesheet"
  href="node_modules/@lgtm-hq/turbo-themes/packages/css/dist/turbo-core.css"
/>
<link
  id="turbo-theme-css"
  rel="stylesheet"
  href="node_modules/@lgtm-hq/turbo-themes/packages/css/dist/themes/catppuccin-mocha.css"
/>

Or with a bundler:

import '@lgtm-hq/turbo-themes/css/core';
import '@lgtm-hq/turbo-themes/css/themes/catppuccin-mocha.css';

Available Classes

The preset adds these color utilities:

Backgrounds

Class Token
bg-turbo-base --turbo-bg-base
bg-turbo-surface --turbo-bg-surface
bg-turbo-overlay --turbo-bg-overlay

Text

Class Token
text-turbo-primary --turbo-text-primary
text-turbo-secondary --turbo-text-secondary
text-turbo-inverse --turbo-text-inverse

Brand & State

Class Token
bg-turbo-brand --turbo-brand-primary
bg-turbo-success --turbo-state-success
bg-turbo-warning --turbo-state-warning
bg-turbo-danger --turbo-state-danger
bg-turbo-info --turbo-state-info

Borders

Class Token
border-turbo-default --turbo-border-default

Usage Examples

Card Component

<div class="bg-turbo-surface border border-turbo-default rounded-lg p-4">
  <h2 class="text-turbo-primary font-semibold">Card Title</h2>
  <p class="text-turbo-secondary">Card description goes here.</p>
</div>

Button

<button class="bg-turbo-brand text-turbo-inverse px-4 py-2 rounded hover:opacity-90">
  Primary Button
</button>

Alert

<div class="bg-turbo-success text-turbo-inverse p-4 rounded">
  Success! Your changes have been saved.
</div>

Theme Switching

Theme switching works automatically. When you change the theme CSS file, Tailwind utilities update because they reference CSS variables. Use the same node_modules/… path as the initial <link> (a site-root /packages/… URL will 404 on a standard install). That form suits plain-HTML pages served from the project root during development; in production, copy the themes directory into your public assets or use the CDN URLs:

function setTheme(themeName) {
  const link = document.getElementById('turbo-theme-css');
  link.href = `node_modules/@lgtm-hq/turbo-themes/packages/css/dist/themes/${themeName}.css`;
}

No rebuild required - changes are instant.

Custom Configuration

Extending the Preset

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
  presets: [require('@lgtm-hq/turbo-themes/adapters/tailwind/preset')],
  theme: {
    extend: {
      // Add your own extensions
      spacing: {
        128: '32rem',
      },
    },
  },
};

Manual Color Configuration

If you prefer not to use the preset, add colors manually:

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
  theme: {
    extend: {
      colors: {
        'turbo-base': 'var(--turbo-bg-base)',
        'turbo-surface': 'var(--turbo-bg-surface)',
        'turbo-overlay': 'var(--turbo-bg-overlay)',
        'turbo-text': 'var(--turbo-text-primary)',
        'turbo-text-secondary': 'var(--turbo-text-secondary)',
        'turbo-text-inverse': 'var(--turbo-text-inverse)',
        'turbo-primary': 'var(--turbo-brand-primary)',
        'turbo-success': 'var(--turbo-state-success)',
        'turbo-warning': 'var(--turbo-state-warning)',
        'turbo-danger': 'var(--turbo-state-danger)',
        'turbo-info': 'var(--turbo-state-info)',
        'turbo-border': 'var(--turbo-border-default)',
      },
    },
  },
};

With Tailwind CDN

For quick prototyping without a build step:

<script src="https://cdn.tailwindcss.com"></script>
<script>
  tailwind.config = {
    theme: {
      extend: {
        colors: {
          'turbo-base': 'var(--turbo-bg-base)',
          'turbo-surface': 'var(--turbo-bg-surface)',
          'turbo-text': 'var(--turbo-text-primary)',
          'turbo-primary': 'var(--turbo-brand-primary)',
          // ... add more as needed
        },
      },
    },
  };
</script>

Next Steps