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

# Setting the object style

<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/ymapsml_setstyle/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/sspcyl?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.GeoObjects">map.GeoObjects</a>, <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/ref/reference/geoXml.load">geoXml.load</a>
</div>
<p>
    YMapsML allows you to set the appearance of objects displayed on the map. The appearance of displayed objects is changed
    using styles. <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/guide/concepts/styles">Styles</a> let you set certain parameters
    for displaying geo objects and generate custom HTML representation using
    <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/guide/concepts/templates">templates</a> (see the <a href="https://yandex.ru/dev/jsapi-v2-1/doc/en/v2-1/examples/cases/ymapsml_ballooncontentstyle">example of using templates</a>).
</p>
<p>
    To define styles, use the <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/representation-Style">repr:Style</a> element, which
    is located in the <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/representation-Representation">repr:Representation</a> element.
</p>
<p>
    To specify which style to apply for displaying an object, set the
   <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/ymaps-GeoObject">ymaps:style</a>
    element in the <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/ymaps-style">ymaps:GeoObject</a> element. It should contain a link
    to a style that was defined in the <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/representation-Style">repr:Style</a> element. The style
    for a collection of geo objects can be set the same way in the
    <a href="https://yandex.ru/dev/maps/ymapsml/doc/en/ref/reference/ymaps-GeoObjectCollection">ymaps:GeoObjectCollection</a> element.
</p>

{% list tabs %}

-   index.html

    ```html
    <!DOCTYPE html>
    <html>
        <head>
            <title>YMapsML examples. Setting styles for objects.</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>
    ```

-   ymapsml_setstyle.js

    ```js
    ymaps.ready(init);

    function init() {
        // Creating a map instance
        var myMap = new ymaps.Map(
            "map",
            {
                center: [61.766513, 34.344165],
                zoom: 12,
            },
            {
                searchControlProvider: "yandex#search",
            }
        );

        // Loading a YMapsML file
        ymaps.geoXml.load("data.xml").then(
            function (res) {
                // Adding geo objects to the map.
                myMap.geoObjects.add(res.geoObjects);
                // Called if loading the YMapsML file was unsuccessful.
            },
            function (error) {
                alert("Error: " + error);
            }
        );
    }
    ```

{% endlist %}
