Next.js Discord

Discord Forum

Tailwind css backround image is not working in NextJS13

Unanswered
Santhosh Prabhakaran posted this in #help-forum
Open in Discord
I'm trying to create an background image in tailwind theme and use it in the component.

The theme looks like,
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./pages/**/*.{js,ts,jsx,tsx,mdx}",
    "./components/**/*.{js,ts,jsx,tsx,mdx}",
    "./app/**/*.{js,ts,jsx,tsx,mdx}",
  ],
  theme: {
    fontFamily: {
      shiseido: ["var(--font-ShiseidoGinza)", "sans-serif"],
      headingExtRegular: ["var(--font-ShiseidoGinzaExtRegular)", "sans-serif"],
      headingExtBold: ["var(--font-ShiseidoGinzaExtBold)", "sans-serif"],
    },
    extend: {
      colors: {
        primary: "#D6001C",
        greyLight: "#787878",
        greyDark: "#343434",
      },
      backgroundImage: {
        "artists-pattern": "url('./app/assets/artists-gradient.png')",
      },
    },
  },
  plugins: [],
};

And I want to use the artists-pattern in my component like this,

<div className="w-full h-[90vh] relative flex bg-artists-pattern">
        {artists.map((artist) => {
          return <div className="" key={artist.id}></div>;
        })}
      </div>


But I'm getting this error,

9 Replies

Cape horse mackerel
I believe there's an issue with path to the image, try:
- backgroundImage: { "artists-pattern": "url('./app/assets/artists-gradient.png')"},
+ backgroundImage: { "artists-pattern": "url('/app/assets/artists-gradient.png')"},
Cape horse mackerel
and if you don't want to extend your theme in the tailwind.config.js you could do
`<div className="bg-[url('path/to/the/image')]" />
Is it normal in this or what ?
Cape horse mackerel
how does your structure look like?
where is tailwind.config.js located?
This
Cape horse mackerel
yeah, don't know why you're not getting any suggestion but it should work
The background image is only working in the page.jsx file which is the home page.
In other components, it's not working and throwing the error as above