# Closed Sidebar by Default

**URL:** https://meta.discourse.org/t/closed-sidebar-by-default/408578
**Category:** Theme component
**Tags:** sidebar
**Created:** [July 27, 2026, 6:13am UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578 "2026-07-27T06:13:08Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [July 27, 2026, 6:13am UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/1 "2026-07-27T06:13:09Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Summary** | allows admins to control the default behaviour of the Discourse sidebar per group |
| 🛠 | **Repository** | [GitHub - nathan-nz/closed-sidebar-by-default: Allows control of the default sidebar behaviour · GitHub](https://github.com/nathan-nz/closed-sidebar-by-default) |
| ❓ | **Install Guide** | [How to install a theme or theme component](https://meta.discourse.org/t/how-do-i-install-a-theme-or-theme-component/63682) |
| 📖 | **New to Discourse Themes?** | [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) |

Install this theme component

This simple Theme Component allows admins to control the default behaviour of the Discourse sidebar per group.

It continues to respect the previous state of the sidebar for that user / device, which means that on reload it gives a nice consistent experience.

### Use case

The most common use-case is a cleaner and simpler UI for casual visitors. For example, if used for Discourse Meta, people would land on this:

 ![image](https://global.discourse-cdn.com/meta/original/4X/3/4/a/34a0f6e3c39d0bc2cc44be58d3b760435bb1710d.jpeg)

instead of the rather busier:

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

### Settings

There is one setting, a simple group selector. It defaults to `anonymous_users` (ID 4), but you can use any group(s).

### Acknowledgements

Many thanks to @don for making the original Theme Component which this is forked from:

> [@Can I default to a hidden sidebar?](https://meta.discourse.org/t/can-i-default-to-a-hidden-sidebar/252984/4):
>
> Hello Nolo, I’ve made a component to achieve this. I hope it helps slightly_smiling_face[https://github.com/VaperinaDEV/closed-sidebar-by-default](https://github.com/VaperinaDEV/closed-sidebar-by-default)

---

<div class="post-metadata">

### Author: ![Andrew\_Rowe](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/andrew_rowe/32/445877_2.png) [@Andrew\_Rowe](https://meta.discourse.org/u/Andrew_Rowe)
#### Post date: [July 27, 2026, 12:16pm UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/2 "2026-07-27T12:16:20Z")

</div>

yes, I have been using Don’s version for some months and really like it. I think when a brand new user lands on the site, it can be a little overwhelming, they have no idea what they are looking at. Hiding the sidebar makes the UI a little less confusing. By my way of thinking, once someone visits the site many times they know where to look for the menu when they need it.

---

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [July 27, 2026, 1:02pm UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/3 "2026-07-27T13:02:41Z")

</div>

> [@nathank](#):
>
> original Theme Component which this is forked from

I like the idea of having the sidebar closed by default. What is the difference between the two theme components?

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [July 27, 2026, 1:04pm UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/4 "2026-07-27T13:04:11Z")

</div>

Don’s version doesn’t have a group setting

---

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [July 27, 2026, 1:07pm UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/5 "2026-07-27T13:07:01Z")

</div>

Thank you very much. I tried to give you a thumbs up but messed it up by clicking the heart too much, and ended up having to wait “54 seconds”! Hence this short message.

---

<div class="post-metadata">

### Author: ![SeizalHong](https://avatars.discourse-cdn.com/v4/letter/s/e95f7d/32.png) [@SeizalHong](https://meta.discourse.org/u/SeizalHong)
#### Post date: [July 28, 2026, 9:11am UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/6 "2026-07-28T09:11:41Z")

</div>

I can see the appeal of having the sidebar closed by default, especially on smaller screens where every bit of space helps. Maybe making it a user preference (or remembering the last state) would be the best compromise, since some people rely on the sidebar constantly while others rarely use it.

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [July 29, 2026, 1:29am UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/7 "2026-07-29T01:29:08Z")

</div>

It does remember the last state usually. However, this component does nix that when active.

Perhaps there is a smarter way to make it so.

---

<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: [July 29, 2026, 5:57am UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/8 "2026-07-29T05:57:59Z")

</div>

Hello 👋

Thanks @nathank for creating a topic for this theme component! 🤗

> [@nathank](#):
>
> It does remember the last state usually. However, this component does nix that when active.

I think something like this should work nowadays. This approach will only close the sidebar on the initial load, and after that, it will fall back to the default behavior (remembering the user’s preference).

```js
import { apiInitializer } from "discourse/lib/api";

const HIDE_SIDEBAR_KEY = "sidebar-hidden";
const INITIALIZED_KEY = "closed-sidebar-by-default-initialized";

export default apiInitializer("1.8.0", (api) => {
  const keyValueStore = api.container.lookup("service:key-value-store");
  const userGroups = settings.user_in_closed_sidebar_groups;

  if (userGroups) {
    if (!keyValueStore.getItem(INITIALIZED_KEY)) {
      keyValueStore.setItem(HIDE_SIDEBAR_KEY, "true");
      keyValueStore.setItem(INITIALIZED_KEY, "true");
    }
  } else {
    if (keyValueStore.getItem(INITIALIZED_KEY)) {
      keyValueStore.removeItem(HIDE_SIDEBAR_KEY);
      keyValueStore.removeItem(INITIALIZED_KEY);
    }
  }
});

```

---

<div class="post-metadata">

### Author: ![Jonathan5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jonathan5/32/197134_2.png) [@Jonathan5](https://meta.discourse.org/u/Jonathan5)
#### Post date: [July 29, 2026, 7:24am UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/9 "2026-07-29T07:24:43Z")

</div>

The component re-hides the sidebar when you refresh a page. It would be cool if it could be a default state but remember any subsequent changes.

---

<div class="post-metadata">

### Author: ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)
#### Post date: [July 29, 2026, 10:36pm UTC](https://meta.discourse.org/t/closed-sidebar-by-default/408578/10 "2026-07-29T22:36:14Z")

</div>

> [@Don](#):
>
> I think something like this should work nowadays. This approach will only close the sidebar on the initial load, and after that, it will fall back to the default behavior (remembering the user’s preference).

Much appreciated @Don!

I’ve rolled that into the TC now, and it works just as advertised. A marked improvement!!
