# Legend

Legends and layer lists are essential for geospatial data visualization, providing context, enhancing map interpretation, and enabling quick actions such as toggling visibility and zooming.

In the Legend tab within Builder, you can control how layers and their legends appear in the map layer list:

* **Layer visibility:** Toggle whether a layer is included in the map layer list for users to interact with.
* **Legend visibility**: Independently toggle whether a layer’s legend is displayed in the map layer list.
* **Custom labels**: Edit legend labels to provide clear and meaningful descriptions for each layer.

<figure><img src="/files/JZ0CjXVBhmNpLvGhkHst" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Pre-generated tileset** layers styled with HexColor are not currently supported in the legend. If you require this functionality, please provide feedback through your CARTO point of contact.
{% endhint %}

### Sort categorical legends

The order of legend entries affects how easily users can interpret your map. For layers styled with categorical or ordinal color scales, you can control the display order of legend items.

To adjust the order:

1. Open the **Legend** tab for the layer.
2. Use the ordering controls to define how categories are sorted.

#### Sorting options

* **Sort by**:
  * **Value**: Orders categories by their frequency in the dataset (most common first by default).
  * **Alphabetically**: Orders categories by label (A → Z).
* **Direction**:
  * Toggle between ascending and descending order.

#### Color consistency

Reordering legend entries does **not** change how data is styled on the map.

Each category keeps its assigned color regardless of its position in the legend. For example, if *Commercial* is displayed in blue, it will remain blue whether it appears first or last. Only the legend’s reading order changes, ensuring visual consistency across the map.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.carto.com/carto-user-manual/maps/legend.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
