'yew with tailwind css
I have tried to follow the steps described in https://dev.to/arctic_hen7/how-to-set-up-tailwind-css-with-yew-and-trunk-il9 to make use of Tailwind CSS in Yew, but it doesn't work.
My test project folder:
Cargo.toml:
[package]
name = "yew-tailwind-app"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yew = { version = "0.19" }
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<link data-trunk href="./tailwind.css" rel="css" />
</head>
<body>
</body>
</html>
The codes in main.rs:
use yew::prelude::*;
#[function_component(App)]
fn app() -> Html {
html! {
<>
<h1>{ "Hello World" }</h1>
<p class={ classes!("bg-red-500") }>{"Test!"}</p>
</>
}
}
fn main() {
yew::start_app::<App>();
}
But I don't see the red background color in "Test!". Can you help?
Solution 1:[1]
I had the same problem. did as it says here https://github.com/matiu2/tailwind-yew-builder . I took tailwind.css from the output directory and put it in the root of the project.
Solution 2:[2]
Tailwind CSS version 3.0 doesn't generate the full CSS by default anymore. This is why my codes didn't work when I made use of Tailwind CLI.
Follow the installation described in: https://tailwindcss.com/docs/installation
And run it in the watch mode:
npx tailwindcss -i ./input.css -o ./output.css --watch
Alternative solution in the development mode: make use of Play CDN by adding the next script in the head tag of index.html:
<script src="https://cdn.tailwindcss.com"></script>
Solution 3:[3]
Add a tailwind.config.js in your project root with the following contents. Modified from Tailwind CSS doc.
module.exports = {
content: ["./src/**/*.{html,rs}"],
theme: {
extend: {},
},
plugins: [],
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dinis_S |
| Solution 2 | ItFlyingStart |
| Solution 3 |


