# How to use interactions to hide and show (toggle) a div?

**URL:** <https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457>\
**Category:** How To\
**Created:** [January 6, 2024, 10:57pm UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457 "2024-01-06T22:57:46Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![johannes](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/johannes/32/6440_2.png) [@johannes](https://forum.bricksbuilder.io/u/johannes)\
**Post date:** [January 6, 2024, 10:57pm UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/1 "2024-01-06T22:57:46Z")

</div>

Hi, I have an icon that I want to use to toggle a divs visiblity.  
Initially the div is hidden (display: none), once the icon is clicked, the div should appear.  
And when the icon is clicked again, the div should be hidden again.

The icon is located outside the div.

I tried using two click interactions on the icon to show and hide the element, targeting the div with a CSS selector. It works to hide it, or to show it, but not to toggle it.

 ![image](https://forum.bricksbuilder.io/uploads/default/original/3X/8/1/813e33369f42cdc513444b3368522b1ab3aeacc1.png)

How can I make this work?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![sinanisler](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/sinanisler/32/34468_2.png) [@sinanisler](https://forum.bricksbuilder.io/u/sinanisler)\
**Post date:** [January 7, 2024, 12:03am UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/2 "2024-01-07T00:03:18Z")

</div>

![image](https://forum.bricksbuilder.io/uploads/default/original/3X/4/1/411f929490d56ad4086d52bd96ff3926a91ff5b4.png)

interaction setup + custom css

```auto
.hiding{
display:none;
}

```

---

<div class="post-metadata">

**Author:** ![johannes](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/johannes/32/6440_2.png) [@johannes](https://forum.bricksbuilder.io/u/johannes)\
**Post date:** [January 7, 2024, 5:39pm UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/3 "2024-01-07T17:39:06Z")

</div>

Thank you @sinanisler , I appreciate it.

But how can I make it initially hidden? I’ve added %root% {display: none;} but then it doesn’t toggle anymore.

Thanks!

---

<div class="post-metadata">

**Author:** ![sinanisler](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/sinanisler/32/34468_2.png) [@sinanisler](https://forum.bricksbuilder.io/u/sinanisler)\
**Post date:** [January 7, 2024, 10:29pm UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/4 "2024-01-07T22:29:46Z")

</div>

ooooh than forget about the hiding lets make .nothiding 😃

here almost the same thing

 ![image](https://forum.bricksbuilder.io/uploads/default/original/3X/1/b/1b5db5143802fdbdb215b1a6b6233111a1355cc8.png)

and button

 ![image](https://forum.bricksbuilder.io/uploads/default/original/3X/5/7/57c504d73d1749984c629336afad8b5d99a68de3.png)

---

<div class="post-metadata">

**Author:** ![johannes](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/johannes/32/6440_2.png) [@johannes](https://forum.bricksbuilder.io/u/johannes)\
**Post date:** [January 8, 2024, 11:26pm UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/5 "2024-01-08T23:26:46Z")

</div>

Thank you very much, this also helped me understand how it works for future instances!

---

<div class="post-metadata">

**Author:** ![yoursoft01](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/y/bbce88/32.png) [@yoursoft01](https://forum.bricksbuilder.io/u/yoursoft01)\
**Post date:** [March 9, 2024, 6:46pm UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/6 "2024-03-09T18:46:30Z")

</div>

Hello,  
pardon my ignorance but I didn’t understand your solution very well !  
I want a hidden element at start to be shown after clicking a button

---

<div class="post-metadata">

**Author:** ![Lucian](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/lucian/32/17575_2.png) [@Lucian](https://forum.bricksbuilder.io/u/Lucian)\
**Post date:** [July 16, 2024, 9:51am UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/7 "2024-07-16T09:51:22Z")

</div>

So wonderfully simple 🙂 Thanks!

---

<div class="post-metadata">

**Author:** ![Webrats](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/w/d26b3c/32.png) [@Webrats](https://forum.bricksbuilder.io/u/Webrats)\
**Post date:** [August 14, 2024, 11:42am UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/8 "2024-08-14T11:42:25Z")

</div>

I replicated this but can’t seem to get this to work. Seems like an issue with display: none, cause if it starts out visible then it does work but if it starts with display:none it does not.

---

<div class="post-metadata">

**Author:** ![FilWi](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/f/f4b2a3/32.png) [@FilWi](https://forum.bricksbuilder.io/u/FilWi)\
**Post date:** [November 15, 2024, 9:52am UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/9 "2024-11-15T09:52:14Z")

</div>

I had the same problem, then I realized that the css on the element overwrites the css on the class.

What I did was remove the display:none on the element, then create a class called “Hidden” with the display:none, and set the element to that class initially. That means that when you toggle the class, the element will become visible.

---

<div class="post-metadata">

**Author:** ![neoxphuse](https://forum.bricksbuilder.io/user_avatar/forum.bricksbuilder.io/neoxphuse/32/24482_2.png) [@neoxphuse](https://forum.bricksbuilder.io/u/neoxphuse)\
**Post date:** [January 21, 2025, 6:15am UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/10 "2025-01-21T06:15:23Z")

</div>

How do you initially set the class to “hidden”?

I can get it to hide when the element is showing first. In the CSS under the element to be hidden as such:

.nav-unhidden {  
display: block; }

.nav-hidden {  
display: none }

The toggle/button is Click | Toggle Attribute | .nav-unhidden \> target CSS selector class

But can’t get it too initially be invisible. I’m assuming the toggle will have to change if I figure this out, because right now it is toggling the .nav-unhidden, and will need to change to .nav-hidden.

---

<div class="post-metadata">

**Author:** ![FilWi](https://forum.bricksbuilder.io/letter_avatar_proxy/v4/letter/f/f4b2a3/32.png) [@FilWi](https://forum.bricksbuilder.io/u/FilWi)\
**Post date:** [January 21, 2025, 8:34am UTC](https://forum.bricksbuilder.io/t/how-to-use-interactions-to-hide-and-show-toggle-a-div/18457/11 "2025-01-21T08:34:45Z")

</div>

I used a single class (ingeniously called .hidden 😉) with the custom CSS “display:none”. Then I set it on the element I wanted to toggle.

Here’s the interaction:

 ![bild](https://forum.bricksbuilder.io/uploads/default/original/3X/f/8/f85db29098e5af6963ee0c4366971bb5a5298552.png)

That’s the simple version. I also created a version that fades it in with animations, but that required a bit more work. First I had to show it, then the animation, then set a key in session storage to show that it was visible so it wouldn’t be possible to click twice and get wonky results.

Then I did the reverse when hiding the element: fade out + hide + remove key from browser storage.

Lastly, I had to remove the key on page load, otherwise it would think that the element was visible if you showed it and then reloaded the page.

I probably messed it up and there’s a simpler solution, but this is what worked for me 🙂
