1. Frameworks
  2. Flask

Installation

Install Preline UI with Flask using Tailwind CSS

Setting up Preline UI in a Flask project using Tailwind CSS.

Prerequisites

This guide assumes you already have a Flask project with Tailwind CSS configured. If you haven't set up Tailwind CSS yet, check out the Tailwind CSS installation guides first.

Quick Flask setup

Python web application framework with Jinja2 templating.

  1. Install Preline UI

    Install preline via npm or yarn in your Flask project directory.

    Terminal
                  
                    npm install preline
                  
                

    Please note, Preline UI uses Tailwind CSS Forms plugin in all form components. Don't forget to install it, if you haven't done so already: npm install -D @tailwindcss/forms

  2. Add the Preline UI CSS Variants and @source for Preline UI JavaScript

    Import the Preline UI CSS Variants file variants.css into your static/css/input.css file, ensuring it comes after the tailwindcss import and add source for Preline UI JavaScript.

    static/css/input.css
                  
                    @import "tailwindcss";
        
                    /* Preline UI */
                    @import "../../node_modules/preline/variants.css";
        
                    /* Plugins */
                    /* @plugin "@tailwindcss/forms"; */
    
                    /* Preline Themes */
                    @import "./themes/theme.css";
                  
                

    Check out the Theme docs to learn more about Preline Themes.

  3. Include Preline UI JavaScript in Flask Templates

    Copy the Preline JavaScript file to your static directory and include it in your Flask templates.

    Terminal
    					  
    							cp node_modules/preline/dist/preline.js static/js/
    					  
    					
    templates/base.html
    					  
    					

Optional Preline UI Styles

Please note, Preline UI comes with some opinionated styles that are applied to components by default. If you want these styles in your project, you may include them into your CSS file. These styles used to come by default in Tailwind v3, so we decided to keep them in Preline UI.

CSS
					  
              /* Adds pointer cursor to buttons */
              @layer base {
                button:not(:disabled),
                [role="button"]:not(:disabled) {
                  cursor: pointer;
                }
              }

              /* Defaults hover styles on all devices */
              @custom-variant hover (&:hover);