# \[Mapbox\] How to change the layer order?

**URL:** <https://community.weweb.io/t/mapbox-how-to-change-the-layer-order/20302>\
**Category:** How do I?\
**Created:** [November 2, 2025, 12:52pm UTC](https://community.weweb.io/t/mapbox-how-to-change-the-layer-order/20302 "2025-11-02T12:52:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WilliamB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/williamb/32/9253_2.png) [@WilliamB](https://community.weweb.io/u/WilliamB)\
**Post date:** [November 2, 2025, 12:52pm UTC](https://community.weweb.io/t/mapbox-how-to-change-the-layer-order/20302/1 "2025-11-02T12:52:59Z")

</div>

Hi,

Does anyone know how to change the layer order on a Mapbox map?

I have a bunch of layers and they are all stacked on top of the base style labels (on top of country/city labels, etc.)

Is there a way to use `addLayer(beforeId)` ?

Thanks !

---

<div class="post-metadata">

**Author:** ![Agustin\_Carozo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/agustin_carozo/32/13231_2.png) [@Agustin\_Carozo](https://community.weweb.io/u/Agustin_Carozo)\
**Post date:** [November 3, 2025, 2:40pm UTC](https://community.weweb.io/t/mapbox-how-to-change-the-layer-order/20302/2 "2025-11-03T14:40:07Z")

</div>

Hi William 👋

I’ve noticed some other members commenting about using layers in Mapbox as being something tricky.

I’m going to ask our team if they know about a potential issue there.

---

<div class="post-metadata">

**Author:** ![Agustin\_Carozo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/agustin_carozo/32/13231_2.png) [@Agustin\_Carozo](https://community.weweb.io/u/Agustin_Carozo)\
**Post date:** [November 4, 2025, 7:17pm UTC](https://community.weweb.io/t/mapbox-how-to-change-the-layer-order/20302/3 "2025-11-04T19:17:27Z")

</div>

Hi @WilliamB can you see this works for you:

Add custom JS action on map load that uses the Mapbox instance variable:

```auto
const map = /* Mapbox element's .instance variable */;

const labelId = map.getStyle().layers.find(l => l.type === 'symbol')?.id;

map.moveLayer('my-layer-id', labelId);

map.addLayer({

id: 'my-layer-id',

type: 'fill',

source: 'my-source',

paint: { 'fill-opacity': 0.5 }

}, labelId);

```

---

<div class="post-metadata">

**Author:** ![WilliamB](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/williamb/32/9253_2.png) [@WilliamB](https://community.weweb.io/u/WilliamB)\
**Post date:** [November 8, 2025, 10:36am UTC](https://community.weweb.io/t/mapbox-how-to-change-the-layer-order/20302/4 "2025-11-08T10:36:45Z")

</div>

Hello Agustin,

Sorry for not replying sooner.

The problem with this method is that my users can filter features from a vector tileset source that is tied to many layers on my mapbox instance and I’m not sure if this will work well.
