23rd Feb '26
/
0 comments

Collapsing all accordion items on mobile in Bricks

In the Bricks Facebook group a user asks:

is there any way to expand the accordion on page load desktop, but have it collapsed on page load mobile? is seems like you cant set these values per screen size

This is not an option out of the box for Accordion (Nestable) element in Bricks.

This Pro tutorial provides the steps to collapse all nestable accordion items at a specific width using a bit of custom CSS (to prevent a flash of expanded content before the JS executes), and JavaScript that checks window.innerWidth <= 480 and, if true, removes .brx-open, sets aria-expanded="false", and hides the content wrapper on all open accordion items.

Reminder: To expand specific accordion items on desktop, enter the item IDs separated by commas like this:

We'll also cover the case where all accordion items can be expanded on desktops and collapsed on mobile devices (to be specific, at a breakpoint).

Step 1

Create a directory named js in your child theme folder. Create a file named accordion-collapse-mobile.js inside it having the following code:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 623 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Making Bricks Nestable Accordion’s First Item Open on Desktop and Closed on Mobile

Making Bricks Nestable Accordion’s First Item Open on Desktop and Closed on Mobile

Using JS to ensure the accordion first entry is open on desktop but closed on mobile.
Categories:
Tags:
Bricks Accordion (Nestable) Element’s Icons

Bricks Accordion (Nestable) Element’s Icons

Adding icon rotations to Bricks' Accordion (Nestable) element when opened.
Categories:
Tags:
Auto-Scroll to the New Open Accordion Item

Auto-Scroll to the New Open Accordion Item

How we can make sure the scroll position is always synced with the accordion when opened.
Categories:
Tags:
Pro
Dynamic Horizontal Posts Accordion in Bricks

Dynamic Horizontal Posts Accordion in Bricks

Creating a horizontal accordion of featured images from posts output by Bricks' query loop.
Categories:
Tags:
Pro
Dynamic Accordion in WordPress using Meta Box and Alpine.js

Dynamic Accordion in WordPress using Meta Box and Alpine.js

This Pro tutorial provides the steps to implement an accordion using Alpine.js in WordPress that pulls the values of sub fields of a Meta Box…
Pro
Dynamic Posts Side Menu with Expandable and Collapsible Accordion Submenus in WordPress

Dynamic Posts Side Menu with Expandable and Collapsible Accordion Submenus in WordPress

This Pro tutorial provides the steps to show all the posts of a specified post type as menu items with accordion functionality for submenus. This…
Categories:
Pro
Accordion Grid Query Loop in Bricks

Accordion Grid Query Loop in Bricks

How to set up a accordion in Bricks such that the "titles" are arranged in a grid with the full width content opening below.
Categories:
Pro
WooCommerce Product Carousel in Bricks

WooCommerce Product Carousel in Bricks

How to set up a carousel that shows WooCommerce products with the product title, price and Add to Cart button for each.
Categories: