FastHTML Tailwind CSS Integration
Welcome to the FastHTML Tailwind CSS integration project! This repository offers components and templates to seamlessly integrate Tailwind CSS into your FastHTML projects. Tailwind CSS is a utility-first CSS framework designed to provide unparalleled flexibility and speed in styling your applications.
📦 Installation
Step 1: Install Tailwind CSS
Tailwind CSS requires Node.js as a dependency. Follow the steps below to install and configure Tailwind CSS for your project.
1.1 Install Tailwind CSS via npm
Run the following commands in your terminal:
npm install -D tailwindcss
npx tailwindcss init
1.2 Configure Template Paths
Update your tailwind.config.js file with the paths to your template files:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,js}"],
theme: {
extend: {},
},
plugins: [],
};
1.3 Add Tailwind Directives to Your CSS
Include the Tailwind CSS directives in your main CSS file (src/input.css):
@tailwind base;
@tailwind components;
@tailwind utilities;
1.4 Start the Tailwind CLI Build Process
Run the following command to start the Tailwind CSS build process:
npx tailwindcss -i ./src/input.css -o ./src/output.css --watch
1.5 Use Custom CSS from fh_tailwindcss
To customize your styles, follow these steps:
Copy the tailwind.css.template file and paste it into your CSS folder.
Import the tailwind.css file into your input.css:
@import './src/static/css/tailwind.css';
It will look like this:
/* Add your Tailwind directives if needed */
@tailwind base;
@tailwind components;
@tailwind utilities;
/* input.css */
@import './src/static/css/tailwind.css';
Step 2: Integrate Tailwind CSS into FastHTML
2.1 Link the Compiled CSS File
Include the compiled CSS file in the <head> of your FastHTML app:
app, rt = fast_app(
pico=False, # We're using Tailwind CSS instead of PicoCSS
hdrs=(
Meta(charset="UTF-8"),
Meta(
name="viewport",
content="width=device-width, initial-scale=1.0, maximum-scale=1.0",
),
Meta(
name="description",
content="FastHTML template using Tailwind CSS for styling",
),
Link(rel="stylesheet", href="/static/css/output.css", type="text/css"),
),
static_path=Path(__file__).parent / "static",
)
2.2 Use Tailwind Utility Classes
You can now use Tailwind CSS classes to style your FastHTML templates and components. Here is an example of a styled button:
<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
Click Me
</button>
🌟 Features
- Utility-First Approach: Tailwind CSS provides a rich set of utility classes for rapid UI development.
- Customizable Design: Extend Tailwind's default configuration to match your project's unique needs.
- Seamless Integration: Quickly add Tailwind CSS to your FastHTML templates and components.
- Real-Time Updates: Leverage the Tailwind CLI for real-time CSS updates during development.
✨ Custom Build Components
This repository provides a set of custom-built components to enhance your development experience. For example, the Modal component:
from fasthtml.common import *
from fh_tailwindcss import GridContainer, LabeledInput
@rt("/")
def get():
return Form(
GridContainer(2,
LabeledInput("User Name", id="user-id", type="text"),
LabeledInput("Email", id="email", type="email")),
GridContainer(1,
LabeledTextarea("Description", id="description", rows=4)))
🚀 Getting Started
To get started, clone this repository and follow the installation steps above. Feel free to explore and contribute by adding new components or optimizing the existing templates.
git clone https://github.com/Epic-Codebase/fh_tailwind.git
🛠️ Contributing
Contributions are welcome! If you have ideas for new components or improvements, please open an issue or submit a pull request.
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
🙌 Acknowledgments
Special thanks to the creators of Tailwind CSS and FastHTML for their amazing tools that make development faster and more enjoyable.
Metadata
Release files for fh-tailwindcss 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fh_tailwindcss-0.0.3.tar.gz | 15.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fh_tailwindcss-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.8 kB
Release files / fh_tailwindcss-0.0.3.tar.gz
| Download URL | fh_tailwindcss-0.0.3.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
75dbe06db599b8e29abffe60c4fee218548f9b8d84efb62630bbd79f553b9ab8
|
|
BLAKE2b-256 checksum How to use checksums |
bfa909ff052b218a4d42fd8722c89c683dfd2d3ba2d828465ab01cdf90b5dd99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 20, 2024.
Transparency logRelease files / fh_tailwindcss-0.0.3-py3-none-any.whl
| Download URL | fh_tailwindcss-0.0.3-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9bd66c9c620015a2e62e7365f5236e974de0c76c9429e9ef2a514344878743f5
|
|
BLAKE2b-256 checksum How to use checksums |
ede3172f637caba9f3293a418c2bfa016e34969361a35b69ea15c2fa7b422ee5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.0.1 CPython/3.12.8
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 20, 2024.
Transparency log