Skip to main content

Integrate Tailwind CSS without JavaScript or npm.

Project description

plain.tailwind

Integrate Tailwind CSS without JavaScript or npm.

Overview

You can use Tailwind CSS in your Plain project without Node.js or npm. This package automatically downloads and manages the Tailwind standalone CLI for you.

Initialize Tailwind in your project:

plain tailwind init

This creates a tailwind.css source file in your project root. Then compile your CSS:

plain tailwind build

For development, use watch mode to automatically recompile when files change:

plain tailwind build --watch

Include the compiled CSS in your templates:

<!DOCTYPE html>
<html>
<head>
    {% tailwind_css %}
</head>
<body>
    <h1 class="text-3xl font-bold text-blue-600">Hello, Tailwind!</h1>
</body>
</html>

CLI commands

plain tailwind init

Sets up Tailwind in your project. This command:

  1. Downloads the Tailwind standalone CLI (if not already installed)
  2. Creates a tailwind.css source file in your project root
plain tailwind init

plain tailwind build

Compiles your Tailwind CSS from the source file to app/assets/tailwind.min.css.

# One-time build
plain tailwind build

# Watch mode for development
plain tailwind build --watch

# Minified build for production
plain tailwind build --minify

The build command automatically installs or updates the Tailwind CLI if needed.

plain tailwind update

Updates to the latest version of Tailwind CSS:

plain tailwind update

This downloads the newest version and updates your pyproject.toml.

Template tag

The tailwind_css template tag includes the compiled CSS file in your templates. Place it in your base template's <head>:

<!DOCTYPE html>
<html>
<head>
    {% tailwind_css %}
</head>
<body>
    {% block content %}{% endblock %}
</body>
</html>

The tag renders a <link> element pointing to your compiled CSS file.

Configuration

Custom source and output paths

You can customize where the source and compiled CSS files are located by setting these in your app/settings.py:

# app/settings.py
from pathlib import Path

# Source CSS file (default: project_root/tailwind.css)
TAILWIND_SRC_PATH = Path("/path/to/your/tailwind.css")

# Compiled CSS output (default: app/assets/tailwind.min.css)
TAILWIND_DIST_PATH = Path("/path/to/output/tailwind.min.css")

The Tailwind version is tracked in your pyproject.toml:

[tool.plain.tailwind]
version = "4.0.0"

When you run plain tailwind build, it automatically checks if your local installation matches this version and updates if needed.

Adding custom CSS

Add custom CSS to your source file (by default tailwind.css at the project root):

@import "tailwindcss";
@import "./.plain/tailwind.css";

/* Add your custom styles here */
.btn-primary {
    @apply bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded;
}

.custom-gradient {
    background: linear-gradient(to right, #4f46e5, #7c3aed);
}

The @import "./.plain/tailwind.css" line includes styles from all your installed Plain packages.

Read the Tailwind docs for more about using custom styles.

Deployment

For production deployments:

  1. Add app/assets/tailwind.min.css to your .gitignore
  2. Run plain tailwind build --minify as part of your deployment process

The build command automatically installs the Tailwind CLI if it is not present, making deployments seamless.

You can automate this by adding a build command to your pyproject.toml:

[tool.plain.build.run]
tailwind = {cmd = "plain tailwind build --minify"}

FAQs

How does this work without Node.js?

Tailwind provides a standalone CLI that bundles everything needed to compile CSS. This package downloads the appropriate binary for your platform (macOS, Linux, or Windows) and manages it for you.

Where is the Tailwind CLI stored?

The Tailwind binary and version information are stored in a .plain directory in your project root. Add this to your .gitignore:

.plain/

How do I use Tailwind classes from other Plain packages?

The @import "./.plain/tailwind.css" line in your source CSS automatically includes @source directives for all installed Plain packages. This ensures Tailwind scans those packages for class usage.

Can I use Tailwind plugins?

The standalone CLI includes all first-party plugins. For third-party plugins that require npm, you would need to use the standard Tailwind installation instead.

Installation

Install the plain.tailwind package from PyPI:

uv add plain.tailwind

Add plain.tailwind to your INSTALLED_PACKAGES:

# app/settings.py
INSTALLED_PACKAGES = [
    # ...
    "plain.tailwind",
]

Add .plain/ to your .gitignore:

.plain/

Initialize Tailwind in your project:

plain tailwind init

Add the tailwind_css template tag to your base template:

<!DOCTYPE html>
<html>
<head>
    {% tailwind_css %}
</head>
<body>
    {% block content %}{% endblock %}
</body>
</html>

Run the build command to compile your CSS:

plain tailwind build --watch

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plain_tailwind-0.20.0.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plain_tailwind-0.20.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file plain_tailwind-0.20.0.tar.gz.

File metadata

  • Download URL: plain_tailwind-0.20.0.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for plain_tailwind-0.20.0.tar.gz
Algorithm Hash digest
SHA256 81f9ed4b6555421e578399345da9d772ea06717f66b620f4f6ed6bf30bdfee68
MD5 a0366bde4282ea378c7990b3c4f07618
BLAKE2b-256 71bfeb7f40aaa546a8c3b44ef98c4895d357baa4dba0bd0ac1e431c2a302b060

See more details on using hashes here.

File details

Details for the file plain_tailwind-0.20.0-py3-none-any.whl.

File metadata

  • Download URL: plain_tailwind-0.20.0-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for plain_tailwind-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3e5502fbdb6b9b2460649a63a1ecd1711c6ebe4b70f375ba85dab5c79db40ed
MD5 169d87b3f0b13359450ffe6e7962c262
BLAKE2b-256 d9a509007691df5254d2bf33050a9e086bde5fd47f7b3fb3cf4db906935ef391

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page