# How to change theme on the fly?

**URL:** <https://meta.discourse.org/t/how-to-change-theme-on-the-fly/108342>\
**Category:** Development\
**Created:** [04.Февраль.2019 20:51:57 UTC](https://meta.discourse.org/t/how-to-change-theme-on-the-fly/108342 "2019-02-04T20:51:57Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)\
**Post date:** [05.Февраль.2019 13:17:59 UTC](https://meta.discourse.org/t/how-to-change-theme-on-the-fly/108342/4 "2019-02-05T13:17:59Z")

</div>

The hamburger theme selector now has an option to change the theme CSS ‘on-the-fly’, and then trigger a reload on the next page navigation.

[https://github.com/discourse/discourse-hamburger-theme-selector/commit/8e20b1cc9a958955845deaf44ed1e6a389c9d7ed](https://github.com/discourse/discourse-hamburger-theme-selector/commit/8e20b1cc9a958955845deaf44ed1e6a389c9d7ed)

I’ve put this behind a setting, and toggled it on Meta so you can try it out. Would you like me to make it default @sam?

@ggurbet to answer your #Development question directly, you can change the theme immediately by using

```plaintext
var themeSelector = require('discourse/lib/theme-selector');
themeSelector.previewTheme([themeId]);

```

That will set the CSS on the current page, but will **not** save the setting. If you want it to persist across navigations you also need

```plaintext
themeSelector.setLocalTheme([themeId], seq);

```

Check the code for the hamburger theme selector to see how to obtain a value for `seq` - you need to make sure not to cause an error for anonymous users (set the seq to 0 in that case).

---

_[View the full topic](https://meta.discourse.org/t/how-to-change-theme-on-the-fly/108342)._
