Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add more than 3 stops for Tailwind gradient

Tags:

tailwind-css

There are three gradient stops- from-*, via-* and to-* are available as Tailwind utilities. I need 1 more gradient stop like via2-* which will support Tailwind's color and percentage. Is it a good idea when I need a gradient color with four stops?

like image 834
Rejaul Avatar asked Nov 29 '25 17:11

Rejaul


1 Answers

You could consider using a custom background image.

Via configuration:

tailwind.config = {
  theme: {
    extend: {
      backgroundImage: ({ theme }) => ({
        foo: `linear-gradient(${theme('colors.blue.500')},${theme('colors.green.500')},${theme('colors.red.500')},${theme('colors.yellow.500')})`,
      }),
    },
  },
};
<script src="https://cdn.tailwindcss.com"></script>

<div class="bg-foo h-40 w-40">

Or as an arbitrary value class:

<script src="https://cdn.tailwindcss.com"></script>

<div class="bg-[linear-gradient(theme(colors.blue.500),theme(colors.green.500),theme(colors.red.500),theme(colors.yellow.500))] h-40 w-40">

Otherwise, you could look at creating your own plugin that creates via2- dynamic class utilities, though you would need to juggle the CSS variables that Tailwind uses internally to generate the gradient from the existing from-, via-, and to- classes.

like image 124
Wongjn Avatar answered Dec 02 '25 07:12

Wongjn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!