# How do I put gradient on thin icons?

**URL:** https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429
**Category:** Development
**Created:** [March 26, 2023, 1:00am UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429 "2023-03-26T01:00:51Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [March 26, 2023, 1:00am UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429/1 "2023-03-26T01:00:51Z")

</div>

I tried everything, I can’t put gradient degrade on icons like these here

 ![image](https://global.discourse-cdn.com/meta/original/4X/a/7/2/a72b2095b3b76af135bfc48a4f0ca0960741eb8c.png)

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [March 27, 2023, 6:30pm UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429/2 "2023-03-27T18:30:35Z")

</div>

I’ve tried everything and I can’t change ☹

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [March 27, 2023, 9:56pm UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429/3 "2023-03-27T21:56:38Z")

</div>

```plaintext
.d-icon.d-icon-d-tracking, .d-icon.d-icon-d-watching {

1. background-image: linear-gradient(to right, #4c6c81, #083263);

}

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/b/d/f/bdfbf75ba903e04a8ca1023af428085cacc13229.png)

```plaintext
.d-icon.d-icon-d-tracking, .d-icon.d-icon-d-watching {

1. color: red;

}

```

 ![image](https://global.discourse-cdn.com/meta/original/4X/f/f/5/ff5b0e743290bf96cf0c2f4bbbba6f272aaa2bbc.png)

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 27, 2023, 11:30pm UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429/4 "2023-03-27T23:30:03Z")

</div>

Hi,

From what I read in [Gradients in SVG - SVG | MDN](https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Gradients), you must add `<linearGradient>` to the SVG.

Others resources:

- [Gradient fills for SVG icons](https://fvsch.com/svg-gradient-fill)
- [SVG Gradients](https://jenkov.com/tutorials/svg/svg-gradients.html)

What you can do is create a hidden SVG in your [theme/component](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) to define your gradients:

```html
<svg aria-hidden="true" focusable="false" style="width:0; height:0; position:absolute;">
  <linearGradient id="my-gradient-1" x2="0" y2="1">
    <stop offset="0%" stop-color="var(--color-stop-1)" />
    <stop offset="50%" stop-color="var(--color-stop-2)" />
  </linearGradient>
  
  <linearGradient id="my-gradient-2">
    <stop offset="0%" stop-color="var(--color-stop-1)" />
    <stop offset="50%" stop-color="var(--color-stop-2)" />
    <stop offset="100%" stop-color="var(--color-stop-3)" />
  </linearGradient>

  <!-- Define specific gradient as needed with a unique ID -->
</svg>

```

Then, in your CSS, you define the color, and you target what SVG elements you want to `fill`:

```css
/* defines gradients color */
#my-gradient-1 {
    --color-stop-1: #a770ef;
    --color-stop-2: #eda58b;
}

#my-gradient-2 {
    --color-stop-1: #2980b9;
    --color-stop-2: #6dd5fa;
    --color-stop-3: #ffffff;
}

.svg-icon, .svg-icon-title {
    /* targets all svg icons */
    fill: url(#my-gradient-1) var(--header_primary-low-mid);
    
    /* targets only chat icon */
    &.d-icon-d-chat {
        fill: url(#my-gradient-2) var(--header_primary-low-mid);
    }
}

```

Note: the second value of `fill` is a fallback color.

 ![NVIDIA_Share_sReu1lscRl](https://global.discourse-cdn.com/meta/original/4X/e/6/a/e6a11f325ed20a7ddbb091bf1491c56fdc7ffd8d.jpeg)

I did not test extensively; this is an example of how you can customize.  
Feel free to check the documentation to make more complex gradients.

I hope that helps!

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [March 28, 2023, 3:41am UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429/5 "2023-03-28T03:41:07Z")

</div>

Hello everything is fine? thank you very much for answering me  
so I had tried this method once, but I couldn’t understand it properly (even more so because I don’t understand English) but it didn’t work, I tried the way you showed me and this time the icons change, but they don’t change for the gradient color, they just change to a gray color, well, let me clear these doubts to see if it is not such an error, what is the name of the text file that you saved? and what name did you put when uploading the theme? where did you put the css, in the css desktop part?

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/0/0/d009e56678b2b409bdb0a6248f367790b91a613b.png)

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 28, 2023, 4:00am UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429/6 "2023-03-28T04:00:00Z")

</div>

I edited my theme CSS/HTML vis Customize → Themes from the admin panel.

1. Either edit your theme or create a theme component here by following [Beginner's guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966#create-new-themes-and-theme-components-7).

2. Click on `Edit CSS/HTML`

3. In `Body` tab, you put the SVG code  
In `Common` tab, you put the CSS

 ![image](https://global.discourse-cdn.com/meta/original/4X/8/5/f/85fad108f3eda0735a54f27ac4fb27b19c5cbc7f.png)  
 ![image](https://global.discourse-cdn.com/meta/original/4X/a/8/1/a810b03c4c203e46607fce06e2a094b4229b00a0.png)

---

<div class="post-metadata">

### Author: ![danielabc](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@danielabc](https://meta.discourse.org/u/danielabc)
#### Post date: [March 31, 2023, 5:34am UTC](https://meta.discourse.org/t/how-do-i-put-gradient-on-thin-icons/259429/7 "2023-03-31T05:34:53Z")

</div>

I had so much trouble with this, and the problem was in the way I was putting it lol, thank you very much for teaching me how to put it in the right place, I will always be grateful for your help, thank you very much
