# Override border-radius variables with theme

**URL:** https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574
**Category:** UX
**Created:** [November 23, 2022, 6:51pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574 "2022-11-23T18:51:56Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [November 23, 2022, 6:51pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/1 "2022-11-23T18:51:57Z")

</div>

Hello,

I tried to override the [new border-radius variables](https://github.com/discourse/discourse/pull/19037) with a remote theme but it seems to the core `:root` variables are always prioritize. I can override these if I create a theme component in admin. Is there a way to override these with theme? What am I missing? 🙂

This tiny change is so useful thanks so much! ❤

* * *

Ok it works as expected just my test site joking me. 🙂

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [November 24, 2022, 4:32am UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/2 "2022-11-24T04:32:57Z")

</div>

> [@Don](#):
>
> Ok it works as expected just my test site joking me. 🙂

Uh it seems that was not a joke 😄 With remote theme I can only override it if I use `!important`.

If I use it like this 🔽

```scss
$border-radius: 2em !important;

:root { 
   --d-button-border-radius: #{$border-radius}; 
   --d-input-border-radius: #{$border-radius}; 
 }

```

Otherwise if I try it like this 🔽

```scss
:root { 
   --d-button-border-radius: 2em; 
   --d-input-border-radius: 2em; 
 }

```

Then the core `:root` variables are prioritized.

What am I missing? 🤔 Thank you! 🙂

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [November 24, 2022, 3:27pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/3 "2022-11-24T15:27:34Z")

</div>

It’s working when I test it in a theme… the core root gets overruled by theme root, as expected.

 ![image](https://global.discourse-cdn.com/meta/original/4X/d/e/b/deb9d180376df8d16797e25b6832cac85491525b.jpeg)

Can you show some more info? Where do you define your root? What does your inspector look like?

---

<div class="post-metadata">

### Author: ![Don](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/don/32/228726_2.png) [@Don](https://meta.discourse.org/u/Don)
#### Post date: [November 24, 2022, 5:44pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/4 "2022-11-24T17:44:03Z")

</div>

Hello Charlie,

Thanks for checking this 🙂

I tried to add in `scss/custom-variables.scss` and import it to the `common.scss`. And I tried to add directly to `common.scss` too.

I just notice now it works if there is no other component (created in admin) assigned to the theme. If I create a component in admin with some css in common section. Then it won’t override the core root variables for me.

It works if the theme has no component or the component Common / CSS is empty.

![Screenshot 2022-11-24 at 18.22.24](https://global.discourse-cdn.com/meta/original/4X/d/b/b/dbb568f698a7deb1826423a05c6c573cffb867e7.png)

 ![Screenshot 2022-11-24 at 18.21.23](https://global.discourse-cdn.com/meta/original/4X/4/5/7/457525d1501b94f8186f35acdebe4f86b86cefef.png)

* * *

If I create a component with some Common / CSS and activate it to the theme.

 ![Screenshot 2022-11-24 at 18.24.21](https://global.discourse-cdn.com/meta/original/4X/d/9/5/d951722aff54697964765b2c5ab5d73dc6525f53.png)

Then it is not working for me.

 ![Screenshot 2022-11-24 at 18.29.42](https://global.discourse-cdn.com/meta/original/4X/f/2/6/f26dfd4234dc8687add14b57810b90f9a55aee86.png)

The `d-default-border-radius` and `d-select-body-border-radius` are custom.

Thanks for the help! 🙂

---

<div class="post-metadata">

### Author: ![chapoi](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chapoi/32/537252_2.png) [@chapoi](https://meta.discourse.org/u/chapoi)
#### Post date: [November 24, 2022, 6:23pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/5 "2022-11-24T18:23:36Z")

</div>

I see. Very interesting. Thanks for the clear steps.

Will see what I come up with. At the moment I’m sceptical there will be a different solution that the !important you’re already using, but will be good to know how/why this is working like this.

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [December 8, 2022, 8:22pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/8 "2022-12-08T20:22:39Z")

</div>

hmm yeah I can repro this… it’s a little strange.

I’ve got a [remote theme](https://github.com/awesomerobot/discourse-test-theme) and all `common.scss` contains is:

```plaintext
:root {
  --d-border-radius: 100px;
}

```

this works and I get rounded buttons and other elements:

 ![Screenshot 2022-12-08 at 2.55.19 PM](https://global.discourse-cdn.com/meta/original/4X/5/f/4/5f4bcfdaef6b40f825a75702c41d1d2d563fd078.png)

Once I add a _local_ theme component that contains CSS, it breaks. I created a local theme component that only contains this in `common.scss`:

```scss
body {
  background: red;
}

```

I get the red background, but the border-radius is gone:

 ![Screenshot 2022-12-08 at 2.57.06 PM](https://global.discourse-cdn.com/meta/original/4X/4/7/c/47c8c8cab617d2ca7d7b082bb21cb36b2c01f59d.png)

The same [component](https://github.com/awesomerobot/discourse-test-theme-component) works fine remotely. I get both the red background and the rounded borders.

@david/@pmusaraj does this have something to do with the order of how remote and local themes are compiled?

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [December 8, 2022, 8:34pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/9 "2022-12-08T20:34:51Z")

</div>

I think it has to do with our magic injection of `variables.scss` into every theme CSS file. Now, we have this in `variables.scss`:

```scss

:root {
  --topic-body-width: #{$topic-body-width};
  --topic-body-width-padding: #{$topic-body-width-padding};
  --topic-avatar-width: #{$topic-avatar-width};
  --d-border-radius: initial;
  --d-nav-pill-border-radius: var(--d-border-radius);
  --d-button-border-radius: var(--d-border-radius);
  --d-input-border-radius: var(--d-border-radius);
}

```

And because we inject that SCSS file into every theme and plugin SCSS file, it gets repeated over and over:

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

The only way to override it currently is to add the override to the last theme stylesheet, only then it gets output last.

I think we need to move this `:root` declaration somewhere global outside of `variables.scss` in core.

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [December 8, 2022, 10:03pm UTC](https://meta.discourse.org/t/override-border-radius-variables-with-theme/246574/10 "2022-12-08T22:03:41Z")

</div>

Aha! thank you so much, I never really processed why those are repeated and just overlooked it completely.

I’ve relocated these to another file so they aren’t repeated, and I confirmed that it solves the problem.

[https://github.com/discourse/discourse/pull/19389](https://github.com/discourse/discourse/pull/19389)
