> For the complete documentation index, see [llms.txt](https://docs.mapbox.com/mapbox-gl-js/llms.txt)

# Style symbols based on pitch

This example uses the [`['pitch']`](https://docs.mapbox.com/style-spec/reference/expressions/#pitch) expression to add in leader lines to labels after a certain pitch threshold is crossed. This is achieved by adding two different layers and setting complementary pitch based filter conditions on them.

> Example code:

**JavaScript**

```html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Style symbols based on pitch</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v3.30.0/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v3.30.0/mapbox-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
</head>
<body>
<div id="map"></div>

<script>
    const map = new mapboxgl.Map({
        // TO MAKE THE MAP APPEAR YOU MUST
        // ADD YOUR ACCESS TOKEN FROM
        // https://account.mapbox.com
        accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
        container: 'map',
        zoom: 13.5,
        pitch: 85,
        bearing: 70,
        center: [-119.53543366513888, 37.74467518164313],
        // Choose from Mapbox's core styles, or make your own style with Mapbox Studio
        style: 'mapbox://styles/mapbox-map-design/claitl3i0002715qm9990tl95'
    });

    map.on('load', () => {
        // Extract JSON representation of an existing layer
        const layer = map
            .getStyle()
            .layers.find((layer) => layer.id === 'natural-point-label');
        // Add in a pitch condition to the existing layers filter
        // so that it only renders when the pitch is low
        const lowPitchFilter = ['all', layer.filter, ['<', ['pitch'], 60]];
        map.setFilter('natural-point-label', lowPitchFilter);

        // Add in styling for leader lines into the layer
        layer.id = 'natural-point-label-elevated';
        // Add a leader line using `icon-image`
        layer.layout['icon-image'] = 'leader_line';
        layer.layout['icon-anchor'] = 'bottom';
        // Elevate the text using text-offset
        layer.layout['text-offset'] = [0, -12.5];
        // Set the filter to only render at high pitch
        const highPitchFilter = ['all', layer.filter, ['>=', ['pitch'], 60]];
        layer.filter = highPitchFilter;

        // Add in a new layer with the updated styling
        map.addLayer(layer, 'natural-point-label');
    });
</script>

</body>
</html>
```

**React**

```jsx
import React, { useEffect, useRef } from 'react';
import * as mapboxgl from 'mapbox-gl/esm';

import 'mapbox-gl/dist/mapbox-gl.css';

const MapboxExample = () => {
  const mapContainerRef = useRef();
  const mapRef = useRef();

  useEffect(() => {
    mapRef.current = new mapboxgl.Map({
      // TO MAKE THE MAP APPEAR YOU MUST
      // ADD YOUR ACCESS TOKEN FROM
      // https://account.mapbox.com
      accessToken: 'YOUR_MAPBOX_ACCESS_TOKEN',
      container: mapContainerRef.current,
      zoom: 13.5,
      pitch: 85,
      bearing: 70,
      center: [-119.53543366513888, 37.74467518164313],
      style: 'mapbox://styles/mapbox-map-design/claitl3i0002715qm9990tl95'
    });

    mapRef.current.on('load', () => {
      const layer = mapRef.current
        .getStyle()
        .layers.find((layer) => layer.id === 'natural-point-label');

      const lowPitchFilter = ['all', layer.filter, ['<', ['pitch'], 60]];
      mapRef.current.setFilter('natural-point-label', lowPitchFilter);

      layer.id = 'natural-point-label-elevated';
      layer.layout['icon-image'] = 'leader_line';
      layer.layout['icon-anchor'] = 'bottom';
      layer.layout['text-offset'] = [0, -12.5];

      const highPitchFilter = ['all', layer.filter, ['>=', ['pitch'], 60]];
      layer.filter = highPitchFilter;

      mapRef.current.addLayer(layer, 'natural-point-label');
    });
  }, []);

  return <div ref={mapContainerRef} id="map" style={{ height: '100%' }}></div>;
};

export default MapboxExample;
```