---
metadata:
  - name: generator
    content: Diplodoc Platform v5.39.1
alternate:
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/button.md
  - https://yandex.com.tr/dev/jsapi-v2-1/doc/ru/v2-1/examples/cases/button.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/jsapi-v2-1/doc/en/llms.txt

# Adding buttons to the map

<iframe id="LIVE-EXAMPLE" style="width:100%;height: 400px;border-radius: 8px;border: 1px solid rgba(92, 94, 102, 0.14);" frameBorder="0" src="https://yastatic.net/s3/front-maps-static/maps-front-jsapi-v2-1/examples/2/out/s3-cases/en/button/index.html" allow="fullscreen"></iframe>

<a target="_blank" rel="noopener noreferrer" style="display: inline-block;margin-top: 10px;cursor: pointer;border-radius: 4px;padding: 9px 12px;background: #151515;color: white;text-decoration: none;font-weight: 500" href="https://codesandbox.io/p/sandbox/ch8qkh?file=index.html">Open in CodeSandbox</a>

<div id="references">
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/ready">ready</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/Map">Map</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/control.Button">control.Button</a>,
    <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/control.Manager">control.Manager</a>
</div>
<p>
    The <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/control.Button">control.Button</a> class lets you create buttons and add them to the map via <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/control.Manager">control.Manager</a>.
</p>
<p>
    A button may have 3 different appearances, depending on the map size and the number of other controls on the map.
    On a small map, the button displays only the icon; on a medium-size map, the text of the button is shown;
    on a large map, the button icon is displayed with the text. You can lock the button in any size or you can specify only the icon
    or text only.
</p>
<p>
    By default, maximum button width is 90 pixels. If your button contains a long text,
    you should set it to the desired maximum size using the maxWidth option.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Examples. Adding buttons to the map</title>
            <meta
                http-equiv="Content-Type"
                content="text/html; charset=UTF-8"
            />
            <!--
            Set your own API-key. Testing key is not valid for other web-sites and services.
            Get your API-key on the Developer Dashboard: https://developer.tech.yandex.ru/keys/
        -->
            
            
            
        </head>
        <body>
            <div id="map"></div>
        </body>
    </html>
    ```

-   button.js

    ```js
    ymaps.ready(init);
    function init() {
        var map = new ymaps.Map("map", {
                center: [59.93772, 30.313622],
                zoom: 10,
                controls: [],
            }),
            firstButton = new ymaps.control.Button("Button");

        map.controls.add(firstButton, { float: "right" });

        var secondButton = new ymaps.control.Button({
            data: {
                // Setting the text and icon for a button.
                content: "Adaptive button",
                // The icon is 16x16 pixels.
                image: "error.svg",
            },
            options: {
                /**
                 * Because the button changes depending on the size of the map, we will give it
                 * three different maxWidth values in the array.
                 */
                maxWidth: [28, 150, 178],
            },
        });
        map.controls.add(secondButton);

        /**
         * We will artificially switch the size of the button every second,
         * in order to show all the options for the button appearance.
         * When resizing the map, these changes will occur automatically.
         */
        function changeSize() {
            var oldSize = secondButton.options.get("size"),
                newSize;
            switch (oldSize) {
                case "small":
                    newSize = "medium";
                    break;
                case "medium":
                    newSize = "large";
                    break;
                case "large":
                    newSize = "small";
                    break;
                default:
                    newSize = "small";
            }
            secondButton.options.set("size", newSize);
        }

        window.setInterval(changeSize, 1000);
    }
    ```

{% endlist %}
