4

I tried to create a project using both tailwindcss and primeng. But after I import Tailwind, the styles of Primeng are not applied any further

I tried using the Tailwind prefix option, but as soon as I import Tailwind the styles of Primeng are not applied anymore. To rule out other reasons, I created a fresh Angular project (Angular version 16) and installed only Tailwindcss and Primeng.

tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
    content: [
        "./src/**/*.{html,ts}",
    ],
    theme: {
        extend: {},
    },
    plugins: [],
    prefix: "tw-",
}

angular.json

{
    "assets": [
    "src/favicon.ico",
    "src/assets"
],
"styles": [
    "src/styles.css"
],
"scripts": []
},

style.css

@tailwind base;
@tailwind components;
@tailwind utilities;

@import "primeng/resources/themes/lara-light-blue/theme.css";
@import "primeng/resources/primeng.css";

In the app component I have a few test divs (Primeng button and Input - Tailwind container with some styles)

After I delete the tailwindcss imports (more precisely @tailwind/base) from the style.css the primeng components have the correct style. but the tailwind styles are lost

5 Answers 5

12

Modify your style.css like this:

@import "tailwindcss/base" layer(tailwindcss);
@import "tailwindcss/components" layer(tailwindcss);
@import "tailwindcss/utilities" layer(tailwindcss);
@import "primeng/resources/themes/lara-light-blue/theme.css";
@import "primeng/resources/primeng.css";

I tried and it's worked for me!

Sign up to request clarification or add additional context in comments.

2 Comments

This is working fine for me, thanks man, you save my time :)
If it does not work You can write like this. And it works for me: @import "../node_modules/tailwindcss/base.css" layer(tailwindcss); @import "../node_modules/tailwindcss/components.css" layer(tailwindcss); @import "../node_modules/tailwindcss/utilities.css" layer(tailwindcss); @import "primeng/resources/themes/lara-light-blue/theme.css"; @import "primeng/resources/primeng.css";
6

add this into your tailwindcss.config.js :

corePlugins: { preflight: false }

I tried and did it

Comments

0

Solutions already posted might work, however, PrimeNG has a reference for this subject in their documentation:

@layer tailwind-base, primeng, tailwind-utilities;
        
@layer tailwind-base {
    @tailwind base;
}

@layer tailwind-utilities {
    @tailwind components;
    @tailwind utilities;
}

Doing this by reordering these layers will prevent tailwind preflight system to replace primeng styles

Source: https://primeng.org/guides/csslayer#tailwind

Comments

0

All the answers referencing the primeng docs didn't work for me. I was wondering why people point to the docs when it is about USING the preflight feature from tailwind ("Tailwind CSS includes a reset utility in base called preflight. If you are using this feature, wrap the base and utilities in separate layers and make sure primeNG layer comes after the base").

If you just disable the preflight feature in the config, some classes won't work anymore (e.g. border).

If you choose the accepted answer, tailwind still changes some primeng styling (e.g. the padding of buttons).

If you want to keep all the primeng styles, disable the preflight feature in the tailwind config and add the needed preflight features for borders (and other features you like e.g. removing list styles) in your styles.css:

@import 'primeng/resources/themes/aura-light-blue/theme.css';
@import 'primeng/resources/primeng.css';

@tailwind base;
@tailwind components;
@tailwind utilities;

// preflight borders
*,
::before,
::after {
  border-width: 0;
  border-style: solid;
  border-color: theme('borderColor.DEFAULT', currentColor);
}

tailwind.config.js:

corePlugins: { preflight: false },

You can add more preflight rules if you want to: https://tailwindcss.com/docs/preflight

Comments

0

I am too using the tailwindcss v4 with NgPrime. soo i got fix by adding this line to the angular.json file at style section.

"styles": [
"src/styles.scss",
"./node_modules/tailwindcss-primeui/v4/index.css"
],

and style scss file should look like this.

@use 'tailwindcss';
@use 'primeicons/primeicons.css';

as you can see i am using @use because @import can't be use after new ruleset for scss or sass.It is working for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.