> For the complete documentation index, see [llms.txt](https://docs.carto.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.carto.com/carto-user-manual/maps/legend.md).

# 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.

The legend opens from the layers button in the bottom-left corner of the map. 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="https://3029946802-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FybPdpmLltPkzGFvz7m8A%2Fuploads%2FlxYTyL0I8Biy5v3CNNVT%2Fimage.png?alt=media&amp;token=ded3e868-b17e-47c4-b9b0-02a5988a493d" 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.

To decide which color each category gets, and keep it when the data changes, use the **Custom** [color scale](/carto-user-manual/maps/layers.md#color-scale).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
