Saanvi Sen
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # How to Create Custom Themes with Tailwind CSS 4? ## Table of Contents: - [Introduction to Tailwind CSS and What's New in Version 4](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#Introduction-to-Tailwind-CSS-and-Whats-New-in-Version-4) - [Setting Up Your Project](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#Setting-Up-Your-Project) - [Exploring the `@theme` Directive and Theme Variables in Tailwind CSS](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#Exploring-the-theme-Directive-and-Theme-Variables-in-Tailwind-CSS) - [Creating Your Own Custom Theme](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#Exploring-the-theme-Directive-and-Theme-Variables-in-Tailwind-CSS) - [Creating Custom Components](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#Creating-Custom-Components) - [Alternatives If You Prefer Not to Create Your Own Theme](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#Alternatives-If-You-Prefer-Not-to-Create-Your-Own-Theme) - [How to Set Up FlyonUI and Use Its Themes in Your Project](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#How-to-Set-Up-FlyonUI-and-Use-Its-Themes-in-Your-Project) - [Conclusion](https://hackmd.io/tvwh4P7QSqOf_yjkQhaBwg?view#Conclusion) ## Introduction to Tailwind CSS and What's New in Version 4 Tailwind CSS is a utility-first framework that makes designing custom websites much easier. Unlike other frameworks that come with pre-designed components, Tailwind provides a set of low-level utility classes that let you style elements directly in your HTML. This approach enables faster, more flexible customization of your designs. ### New Features in Tailwind CSS v4: - **Boosted Performance:** With the new Oxide engine, Tailwind v4 speeds up the build process, making full builds up to five times faster and incremental builds more than 100 times quicker. - **Easier Setup:** Version 4 simplifies installation by reducing dependencies and eliminating complex configuration steps. Now, all you need is a single line of code in your CSS file to get started. - **CSS-First Customization:** Customizing Tailwind is now more straightforward and happens directly within CSS using the `@theme` directive, removing the need for JavaScript-based setups. - **Automatic Content Detection:** The framework now automatically detects your template files, saving you the hassle of manual configuration. - **Advanced CSS Features:** Tailwind CSS v4 takes advantage of modern CSS features such as native cascade layers, custom properties, and the `color-mix()` function, giving developers more control over styling. - **Support for Container Queries:** With built-in container queries support, Tailwind v4 allows you to apply styles based on the size of parent containers, making responsive design even easier to implement. These updates make Tailwind CSS v4 a more powerful tool for creating fast, responsive, and highly customizable web applications. ## Setting Up Your Project ### Step 1: Install Tailwind CSS Get started by installing Tailwind CSS and the @tailwindcss/cli packages. ```bash npm install tailwindcss @tailwindcss/cli ``` ### Step 2: Import Tailwind in your CSS Include the `@import "tailwindcss";` statement in your primary CSS file. ```css @import "tailwindcss"; ``` ### Step 3: Start the Tailwind CLI build process Run the CLI tool to analyze your source files for classes and generate the final CSS. ```bash npx @tailwindcss/cli -i ./src/main.css -o ./src/new.css --watch ``` ### Step 4: Start using Tailwind in your HTML Link your compiled CSS file in the `<head>` section and begin applying Tailwind’s utility classes to style your content. ```html <html> <head> <link href="./new.css" rel="stylesheet"> </head> <body> <h1 class="text-3xl text-blue-300 font-semibold"> Set Up is Complete! </h1> </body> </html> ``` ## Exploring the `@theme` Directive and Theme Variables in Tailwind CSS In Tailwind CSS, the `@theme` directive lets you create custom design tokens—such as colors, fonts, and spacing—by defining CSS variables. These variables serve as the core for Tailwind's utility classes, helping you maintain a consistent and easily adjustable design system. To customize your project's color palette, you can define new color variables within the `@theme` block: ```css @import "tailwindcss"; @theme { --color-primary: #3490dc; --color-secondary: #ffed4a; --color-accent: #38c172; } ``` In the code above, `--font-*`*, `--color-*`*, and `--radius-*` are examples of theme variable namespaces. By creating new variables within these namespaces, you unlock corresponding utilities and variants in your project. For a full list of namespaces supported by Tailwind, you can check out the official [documentation](https://tailwindcss.com/docs/theme#theme-variable-namespaces). ### Using Theme Variables in Your Custom CSS In addition to utility classes, you can also use theme variables in your custom CSS to maintain consistency with your overall design system: ```css .button { background-color: var(--color-primary); color: var(--color-white); padding: 0.5rem 1rem; border-radius: 0.25rem; } ``` ### Advantages of the `@theme` Directive - **Centralized Design Control**: Define all your design tokens in one place, making global design changes simpler. - **Better Consistency**: Achieve uniform styling throughout your project by using shared design values. - **Easier Maintenance**: Quickly adjust design elements by updating theme variables, without the need to make changes in multiple locations. ## Creating Your Own Custom Theme To start, we will define a set of CSS variables that represent our theme’s design tokens, including fonts, colors, and border radius. These variables will lay the foundation for building our unique custom theme. ```css @theme{ --font-display: "Lato", "sans-serif"; --color-primary: oklch(82% 0.111 230.318); --color-secondary: oklch(80% 0.114 19.571); --color-accent: oklch78% 0.115 274.713); --color-base: oklch(98% 0 0); --tw-shadow-color: oklch(0.17 0.0296 208.59 / 40%); --radius-box: 0.5rem; --radius-btn: 0.375rem; } ``` Now you have your own custom theme in place. ![custom theme example](https://hackmd.io/_uploads/B1v0nCjRye.png) ## Creating Custom Components In Tailwind CSS, you can easily create custom components by using the `@layer components` directive. This allows you to define reusable styles for elements throughout your project. Below is an example of how you can create custom button components: ```css @layer components { .btn { @apply bg-neutral-600 text-neutral-200 font-medium py-2 px-4 rounded-btn active:scale-95 transition duration-300; } .btn-primary { @apply bg-primary text-gray-700; } .btn-secondary { @apply bg-secondary text-gray-700; } .btn-accent { @apply bg-accent text-gray-700; } } ``` ### What’s Happening in the Code - The `.btn` class defines the base styling for the button, including padding, colors, border-radius, and a smooth transition effect for interactions. - The `.btn-primary`, `.btn-secondary`, and `.btn-accent` classes add variations, customizing the button's background color using your theme's color variables. Custom components make your styling process more efficient and help keep your code organized. ## Alternatives If You Prefer Not to Create Your Own Theme If you'd rather not build your own theme from scratch, FlyonUI - [Tailwind UI](https://flyonui.com/) Component Library is a great alternative. It’s a free, open-source Tailwind CSS component library that comes with semantic classes and 12 pre-made themes that look great right out of the box. FlyonUI includes a variety of pre-designed CSS and JavaScript components, plus useful third-party plugins to help speed up your development. Each theme is easy to customize, so you can adjust it to fit your project without starting from scratch. Here are the themes that FlyonUI provides. ## How to Set Up FlyonUI and Use Its Themes in Your Project ### Step 1: Install FlyonUI Start by adding FlyonUI to your project with this command: ```bash npm install flyonui ``` ### Step 2: Add FlyonUI plugin Next, add the FlyonUI plugin to your `global.css` file. ```bash @plugin "flyonui"; @import "flyonui/variants.css"; @import "./node_modules/flyonui/variants.css"; /* Require only if you want to use FlyonUI JS component */ ``` ### Step 3: Activate all themes To enable all 12 pre-built themes, set the `themes` option to `all`: ```css @import "tailwindcss"; @plugin "flyonui" { themes: all; } ``` Or, if you prefer to use a specific theme, for example, `mintlify` ,use this: ```css @import "tailwindcss"; @plugin "flyonui" { themes: mintlify; } ``` ### Step 4: Apply theme to your HTML To apply the `mintlify` theme to your page, simply use this HTML: ```html <html data-theme="mintlify"> <body> <script src="../node_modules/flyonui/flyonui.js"></script> //Require only if you want to use FlyonUI JS component </body> </html> ``` And you're all set! Now you can start using the theme in your template.😃 ## Conclusion Building a custom theme with Tailwind CSS gives you full control over your design, allowing you to create a unique and cohesive look for your project. By understanding how to work with Tailwind's `@theme` directive, you can easily customize colors, fonts, and other design tokens to match your vision. And if creating your own theme feels like too much work, FlyonUI is a great alternative with pre-made, customizable themes that can save you time and effort. Whether you choose to design from scratch or use a [Tailwind Components library](https://flyonui.com/) like FlyonUI, Tailwind CSS provides all the flexibility and tools you need to build beautiful, responsive websites quickly and efficiently. The possibilities are endless—so go ahead and start experimenting with your own designs!

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully