#tailwind #leptos #css #clx

leptos_ui

Macros to build UI components easily with Leptos and Tailwind CSS

82 releases

Uses new Rust 2024

0.3.22 Apr 3, 2026
0.3.21 Mar 9, 2026
0.3.20 Jan 30, 2026
0.3.17 Nov 1, 2025
0.1.8 Mar 31, 2025

#138 in Accessibility

Download history 53/week @ 2026-02-20 148/week @ 2026-02-27 429/week @ 2026-03-06 249/week @ 2026-03-13 185/week @ 2026-03-20 240/week @ 2026-03-27 251/week @ 2026-04-03 413/week @ 2026-04-10 408/week @ 2026-04-17 340/week @ 2026-04-24 301/week @ 2026-05-01 449/week @ 2026-05-08 447/week @ 2026-05-15 580/week @ 2026-05-22 590/week @ 2026-05-29 671/week @ 2026-06-05

2,352 downloads per month

MIT license

170KB
3K SLoC

Leptos UI

Macros to build UI components easily with Leptos and Tailwind CSS. Built on top of tw_merge.

Features

  • clx!: Creates components with children
  • void!: Creates self-closing components (<img />, <input />, etc.)

Both support automatic data-name attributes and Tailwind CSS class merging, without class conflicts.

Example in Production

This crate is used in rust-ui.com โ€” check it out to see Leptos UI and Tailwind CSS in action :)

Usage

Basic Component with clx!

// components/ui/card.rs
use leptos::prelude::*;
use leptos_ui::clx;

mod components {
    use super::*;
    clx! {Card, div, "rounded-lg p-4", "bg-sky-500"} // ๐Ÿฉต
}

pub use components::*;

// components/demos/demo_card.rs
#[component]
pub fn DemoCard() -> impl IntoView {
    view! {
        <Card>"Card bg-sky-500 ๐Ÿฉต"</Card>
        <Card class="bg-orange-500">"Card bg-orange-500 ๐Ÿงก"</Card>
        // โ””โ”€โ”€> ๐Ÿคฏ NO CONFLICT CLASS!!
    }
}

Basic component with void!

use leptos::prelude::*;
use leptos_ui::void;

// Define self-closing components
void! {MyImage, img, "rounded-lg border"}
void! {MyInput, input, "px-3 py-2 border rounded"}
void! {MyDiv, div, "w-full h-4 bg-gray-200"}

#[component]
pub fn Demo() -> impl IntoView {
    view! {
        // ...
        <MyImage attr:src="test.jpg" class="w-32" />
        <Input prop:value=move || url().to_string() attr:readonly=true class="flex-1" />
        <MyDiv class="bg-blue-500" />
    }
}

VSCode Tailwind CSS IntelliSense

Enable autocomplete and conflict detection for Tailwind classes inside clx! and void! macros:

  1. Install the "Tailwind CSS IntelliSense" Visual Studio Code extension

  2. Add the following to your settings.json:

{
  "tailwindCSS.includeLanguages": {
    "rust": "html"
  },
  "tailwindCSS.experimental.classRegex": [
    ["clx!\\s*\\{[^,]*,\\s*[^,]*,\\s*\"([^\"]*)\""],
    ["void!\\s*\\{[^,]*,\\s*[^,]*,\\s*\"([^\"]*)\""],
    ["tw_merge!\\(([^)]*)\\)"]
  ]
}

This enables:

  • Tailwind class autocomplete in Rust files
  • Real-time conflict detection (e.g., w-full w-fit)
  • Hover documentation for Tailwind classes

Tailwind IntelliSense Conflict Detection

Changelog

September 2025 - leptos_ui v0.2 Breaking Changes

We refactored the leptos_ui crate with breaking changes.

New macro system:

  • clx!: Elements with children
  • void!: Self-closing elements (no children)

See MDN Docs for reference about void elements.

Attribute changes: Removed direct props from macros. Use attr:* and prop:* pattern instead:

// Define component
void! {MyInput, input, "border border-input"}

// Before
<MyInput value=move || url().to_string() readonly=true class="flex-1" />

// After
<MyInput prop:value=move || url().to_string() attr:readonly=true class="flex-1" />

License

This project is licensed under the MIT License. See the LICENSE file for details.

Dependencies

~24โ€“32MB
~604K SLoC