Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a css gradient with single color

I am trying to generate a gradient using one single color and then varying the brightness or some other related variable.

Is it possible to do so ?

like image 444
Ninja420 Avatar asked May 12 '26 16:05

Ninja420


1 Answers

Use a back/white layer on the top of your single color as a gradient

html {
  background:
    linear-gradient(90deg,rgb(255 255 255/50%),rgb(0 0 0/50%)),
    red; /* here is your single color */
}

Another idea is to use color-mix() to create different shades from the same color

html {
  --c: red; /* the main color */

  background:
    linear-gradient(90deg,
      color-mix(in srgb,var(--c), #fff 30%), /* we mix with white for brighter */
      color-mix(in srgb,var(--c), #000 30%)  /* we mix with black for darker */
     )
} 
like image 57
Temani Afif Avatar answered May 15 '26 09:05

Temani Afif



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!