Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

azc99's avatar
Level 4

laravel 11 tailwind gradient

I'm refactoring an existing laravel 10 app. installed laravel 11 app with herd and my gradient for landing page no longer works. laravel 10 was tailwind 3.2 now tailwind 3.4. same code...

tailwind.config.js

import defaultTheme from 'tailwindcss/defaultTheme';
import forms from '@tailwindcss/forms';
import typography from '@tailwindcss/typography';

/** @type {import('tailwindcss').Config} */
export default {
    content: [
        './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
        './vendor/laravel/jetstream/**/*.blade.php',
        './storage/framework/views/*.php',
        './resources/views/**/*.blade.php',
    ],

    theme: {
        colors: {
            'hkcolor': '#004990',
        },
        fontFamily: {
            sans: ['Figtree', ...defaultTheme.fontFamily.sans],
            helvlt: ["HelveticaNeueLTStd-LT", "cursive"],
            helmd: ["HelveticaNeueLTStd-MD", "cursive"],
            helcn: ["HelveticaNeueLTStd-CN", "cursive"],
            start: ['"Start"', '"cursive"']
        },
        backgroundImage: {
            'gavel': "url('/public/assets/image001.png')",
        },
    },

    plugins: [forms, typography],
};

  <div class="bg-gavel bg-cover h-auto">

    <div class="h-screen bg-gradient-to-l from-transparent to-white">
...```

does anybody have any ideas about this?
0 likes
5 replies
LaryAI's avatar
Level 58

It seems like you're having trouble with the gradient background in your Laravel 11 application after upgrading from Laravel 10 and Tailwind CSS 3.2 to Tailwind CSS 3.4. The code you've provided looks correct for defining a custom background image and using a gradient overlay. However, there are a few things you can check to ensure everything is working as expected:

  1. Tailwind CSS Version: Ensure that you are indeed using Tailwind CSS 3.4 by checking your package.json file. If necessary, update Tailwind CSS by running npm update tailwindcss or yarn upgrade tailwindcss.

  2. Purge/Clean Cache: Since you've upgraded your application, make sure to clear any cached styles that might be interfering. You can do this by running npm run dev or npm run build to recompile your assets.

  3. Check the Path: The path to your background image is specified as url('/public/assets/image001.png'). Make sure that the path is correct and the image is accessible. In a typical Laravel application, the public directory is the document root, so you might need to change it to url('/assets/image001.png').

  4. Inspect the Element: Use your browser's developer tools to inspect the element with the bg-gavel class. Check if the background image is being applied and if there are any overriding styles that might be causing the issue.

  5. Tailwind JIT Mode: If you're using Just-In-Time (JIT) mode in Tailwind CSS, ensure that your tailwind.config.js file has the content array properly configured to include all the templates where your classes are used.

Here's a revised tailwind.config.js with the corrected image path:

import defaultTheme from 'tailwindcss/defaultTheme';
import forms from '@tailwindcss/forms';
import typography from '@tailwindcss/typography';

export default {
    content: [
        // ... other paths
        './resources/views/**/*.blade.php',
    ],

    theme: {
        // ... other theme settings
        backgroundImage: {
            'gavel': "url('/assets/image001.png')",
        },
    },

    plugins: [forms, typography],
};

And your HTML should remain the same:

<div class="bg-gavel bg-cover h-auto">
  <div class="h-screen bg-gradient-to-l from-transparent to-white">
    <!-- ... -->
  </div>
</div>

If after checking all these points the issue persists, consider looking for any breaking changes in the Tailwind CSS release notes between versions 3.2 and 3.4 that might affect background gradients or images.

azc99's avatar
Level 4

the path to the background image will not compile with "/assets... only "/public/assets... or full path "https://hk20.test/assets... cleared cache, and npm run build, npm run dev I dont see any breaking changes for gradient to 3.4 I misspoke my laravel 10 app used tailwind 3.1

gych's avatar
gych
Best Answer
Level 29

Only thing that I can see that's wrong in your config is that you're using not using the correct config for ESM.

Use theme.extend

export default {
    content: [
		'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
        './vendor/laravel/jetstream/**/*.blade.php',
        './storage/framework/views/*.php',
        './resources/views/**/*.blade.php',
    ],
    theme: {
		extend: {
			colors: {
           		'hkcolor': '#004990',
       		},
        	fontFamily: {
            	sans: ['Figtree', ...defaultTheme.fontFamily.sans],
            	helvlt: ["HelveticaNeueLTStd-LT", "cursive"],
           		helmd: ["HelveticaNeueLTStd-MD", "cursive"],
            	helcn: ["HelveticaNeueLTStd-CN", "cursive"],
           		start: ['"Start"', '"cursive"']
        	},
        	backgroundImage: {
            	'gavel': "url('/public/assets/image001.png')",
        	},
		}
    },
    plugins: [forms, typography],
};
2 likes
azc99's avatar
Level 4

You nailed it! Thanks. re-formated tailwind.config.js and all is well. Continuing my laravel 11 journey.

gych's avatar

@azc99 No problem :) I'm glad it works, goodluck with your journey

1 like

Please or to participate in this conversation.