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

# Hosting maps in the hidden container

<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/hiddendiv/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/n2sjlx?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>
    The map content fills the container it is in. At the time of initialization, the map must be able to detect the dimensions of the container.
</p>
<p>
    If the container isn't ready at the time of map initialization, the map dimensions will be null (0x0), which means that the map won't be visible.
</p>
<p>
    The map is invisible on the inactive jQuery.UI tab because the CSS 'display: none' property is used for hiding tabs.
An element that has 'display: none' doesn't know its actual dimensions. The easiest solution is to initiate calculating map sizes when switching tabs, by calling the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/map.Container-docpage/#fitToViewport">fitToViewport()</a> command. Another workaround for the problem in the example (using jQuery.UI) is to use an alternative method for hiding tabs  by redefining the standard jQuery.UI classes:
</p>
<p>
    .ui-tabs .ui-tabs-hide {
    position: absolute !important;
    left: -10000px !important;
    display: block !important;
    }
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>

    <html>
        <head>
            <title>Examples. Hosting maps in the hidden container</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/
        -->
            

            <!--
            Main JQuery library.
            Yandex provides hosting of JavaScript libraries
        -->
            

            <!-- JQuery.UI library. Use it to work with tabs -->
            

            <!-- CSS JQuery.UI tabs. Used for rendering tabs -->
            <link
                rel="stylesheet"
                href="https://yandex.st/jquery-ui/1.8.23/themes/humanity/jquery.ui.all.min.css"
                type="text/css"
            />

            
        </head>

        <body>
            <div id="tabs" style="width: 100%">
                <ul>
                    <li><a href="#tab-1">Description</a></li>
                    <li><a href="#tab-2">Map</a></li>
                </ul>
                <div id="tab-1">
                    <p>The map of Moscow is shown on the Map tab</p>
                </div>
                <div
                    id="tab-2"
                    style="width: 100%; height: 300px; padding: 0;"
                ></div>
            </div>
        </body>
    </html>
    ```

-   hiddendiv.js

    ```js
    ymaps.ready(init);

    var myMap;

    function init() {
        /**
         * Initializing tabs.
         * After executing the tabs() command, tab-2 gets style='display:none'.
         * The map will be initialized, but the size will be null.
         * This is a good thing in this case, since the invisible map won't load invisible tiles.
         */
        $("#tabs").tabs();
        myMap = new ymaps.Map("tab-2", {
            center: [55.76, 37.64], // Moscow
            zoom: 10,
        });

        /**
         * We'll recalculate the map size when the new tab is displayed.
         * The map will get the maximum possible values when its tab is activated
         * and null values when the first tab is selected.
         * We'll subscribe to the 'tabsshow' event (not 'tabselect',
         * since it requires that the element with the map is already visible).
         */
        $("#tabs").bind("tabsshow", function (event, ui) {
            myMap.container.fitToViewport();
        });
    }
    ```

{% endlist %}
