Skip to content

How to Store and Access Gradient Values in @theme (Tailwind CSS v4)? #17874

Answered by wongjn
Arifulislam5577 asked this question in Help
Discussion options

You must be logged in to vote

If you define them with --background-image prefix, you don't need to use arbitrary value syntax:

@theme {
  --background-image-gradient-1: linear-gradient(135deg, #a585ff 0%, #ffc2ad 100%);
  --background-image-gradient-2: linear-gradient(135deg, #f9eb57 0%, #f99988 100%);
  --background-image-gradient-3: linear-gradient(135deg, #83e7ee 0%, #f9eb57 100%);
  --background-image-gradient-4: linear-gradient(135deg, #864ffe 0%, #23eed6 100%);
}
<div class="bg-gradient-1">Gradient Background</div>

If you want to keep using the --color-gradient-* naming scheme, you'd need to type-hint the value with image::

<div class="bg-(image:--color-gradient-1)">Gradient Background</div>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Arifulislam5577
Comment options

Answer selected by Arifulislam5577
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants