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

# Resizing 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/fillcontainer/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/ktj8ts?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/map.Container">map.Container</a>
</div>
<p>
    Map size is determined when it is created by the container manager.
    After this, the map does not track possible changes to its size.
    In order for the map to change its size to the current size,
    call the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/map.Container#fitToViewport">fitToViewport()</a> function.
</p>
<p>
    If you copy the full code of the example to a new HTML document,
    the opened map will take up the entire browser viewport.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>Examples. Resizing 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="container">
                <input type="button" value="Expand/Collapse" id="toggler" />
                <input type="checkbox" value="Resize the map" id="checkbox" />
                <label for="checkbox">Inform the map</label><br /><br />
                <div id="map" class="smallMap"></div>
            </div>
        </body>
    </html>
    ```

-   fillcontainer.js

    ```js
    ymaps.ready(init);

    var myMap,
        bigMap = false;

    function init() {
        myMap = new ymaps.Map(
            "map",
            {
                center: [55.755768, 37.617671],
                zoom: 10,
            },
            {
                /**
                 * For complex rebuilds, we can set automatic updates to the map
                 * when the container is resized.
                 * For simple changes to the size of the container, we recommend updating the map programmatically.
                 * autoFitToViewport: 'always'
                 */
                searchControlProvider: "yandex#search",
            }
        );
        $("#toggler").click(toggle);
    }

    function toggle() {
        bigMap = !bigMap;

        /**
         * Adding/removing a CSS class that defines the dimensions of the map container
         * in absolute units (300x200 px).
         */
        if (bigMap) {
            $("#map").removeClass("smallMap");
        } else {
            $("#map").addClass("smallMap");
        }

        /**
         * If set, we tell the map that it should match its dimensions
         * to the dimensions of the container.
         */
        if ($("#checkbox").prop("checked")) {
            myMap.container.fitToViewport();
        }
    }
    ```

{% endlist %}
