/* * Always set the map height explicitly to define the size of the div element * that contains the map. */#map{height:100%;}/* * Optional: Makes the sample page fill the window. */html,body{height:100%;margin:0;padding:0;}/* HTML marker styles */.price-tag{background-color:#4285F4;border-radius:8px;color:#FFFFFF;font-size:14px;padding:10px15px;position:relative;transform:translateY(-8px);}.price-tag::after{content:"";position:absolute;left:50%;top:100%;transform:translate(-50%,0);width:0;height:0;border-left:8pxsolidtransparent;border-right:8pxsolidtransparent;border-top:8pxsolid#4285F4;}
Git and Node.js are required to run this sample locally. Follow these instructions to install Node.js and NPM. The following commands clone, install dependencies and start the sample application.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[[["\u003cp\u003eThis example demonstrates how to create a custom HTML marker on a Google Map, replacing the default icon.\u003c/p\u003e\n"],["\u003cp\u003eThe marker is created using the \u003ccode\u003eAdvancedMarkerElement\u003c/code\u003e class and displays a price tag with custom styling.\u003c/p\u003e\n"],["\u003cp\u003eSample code is provided in both TypeScript and JavaScript, along with the corresponding HTML and CSS.\u003c/p\u003e\n"],["\u003cp\u003eUsers can experiment with the sample using JSFiddle or Google Cloud Shell, or clone and run it locally with Git and Node.js.\u003c/p\u003e\n"]]],["The provided code demonstrates the creation of a custom HTML marker on a Google Map. It initializes a map centered at latitude 37.42, longitude -122.1 with zoom level 14. A div element with the text \"$2.5M\" is created and styled using CSS, then used as the content of a new `AdvancedMarkerElement`. The marker is placed on the map at the specified coordinates, replacing the default icon with the custom HTML and styling defined.\n"],null,["This example shows creating a new marker, replacing the default icon with\ncustom HTML and CSS.\n\nRead the\n[documentation](/maps/documentation/javascript/advanced-markers/html-markers). \n\nTypeScript \n\n```typescript\nasync function initMap() {\n // Request needed libraries.\n const { Map } = await google.maps.importLibrary(\"maps\") as google.maps.MapsLibrary;\n const { AdvancedMarkerElement } = await google.maps.importLibrary(\"marker\") as google.maps.MarkerLibrary;\n\n const map = new Map(document.getElementById('map') as HTMLElement, {\n center: { lat: 37.42, lng: -122.1 },\n zoom: 14,\n mapId: '4504f8b37365c3d0',\n });\n\n const priceTag = document.createElement('div');\n priceTag.className = 'price-tag';\n priceTag.textContent = '$2.5M';\n\n const marker = new AdvancedMarkerElement({\n map,\n position: { lat: 37.42, lng: -122.1 },\n content: priceTag,\n });\n}\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/cca4025329cd07519d74fb31e5f718e5365f32af/samples/advanced-markers-html-simple/index.ts#L8-L31\n```\n| **Note:** Read the [guide](/maps/documentation/javascript/using-typescript) on using TypeScript and Google Maps.\n\nJavaScript \n\n```javascript\nasync function initMap() {\n // Request needed libraries.\n const { Map } = await google.maps.importLibrary(\"maps\");\n const { AdvancedMarkerElement } = await google.maps.importLibrary(\"marker\");\n const map = new Map(document.getElementById('map'), {\n center: { lat: 37.42, lng: -122.1 },\n zoom: 14,\n mapId: '4504f8b37365c3d0',\n });\n const priceTag = document.createElement('div');\n priceTag.className = 'price-tag';\n priceTag.textContent = '$2.5M';\n const marker = new AdvancedMarkerElement({\n map,\n position: { lat: 37.42, lng: -122.1 },\n content: priceTag,\n });\n}\ninitMap();https://github.com/googlemaps-samples/js-api-samples/blob/cca4025329cd07519d74fb31e5f718e5365f32af/dist/samples/advanced-markers-html-simple/docs/index.js#L8-L28\n```\n| **Note:** The JavaScript is compiled from the TypeScript snippet.\n\nCSS \n\n```css\n/* \n * Always set the map height explicitly to define the size of the div element\n * that contains the map. \n */\n#map {\n height: 100%;\n}\n\n/* \n * Optional: Makes the sample page fill the window. \n */\nhtml,\nbody {\n height: 100%;\n margin: 0;\n padding: 0;\n}\n\n/* HTML marker styles */\n.price-tag {\n background-color: #4285F4;\n border-radius: 8px;\n color: #FFFFFF;\n font-size: 14px;\n padding: 10px 15px;\n position: relative;\n transform: translateY(-8px);\n}\n\n.price-tag::after {\n content: \"\";\n position: absolute;\n left: 50%;\n top: 100%;\n transform: translate(-50%, 0);\n width: 0;\n height: 0;\n border-left: 8px solid transparent;\n border-right: 8px solid transparent;\n border-top: 8px solid #4285F4;\n}\nhttps://github.com/googlemaps-samples/js-api-samples/blob/cca4025329cd07519d74fb31e5f718e5365f32af/dist/samples/advanced-markers-html-simple/docs/style.css#L7-L48\n```\n\nHTML \n\n```html\n\u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003eAdvanced Marker Simple HTML\u003c/title\u003e\n\n \u003clink rel=\"stylesheet\" type=\"text/css\" href=\"./style.css\" /\u003e\n \u003cscript type=\"module\" src=\"./index.js\"\u003e\u003c/script\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"map\"\u003e\u003c/div\u003e\n\n \u003c!-- prettier-ignore --\u003e\n \u003cscript\u003e(g=\u003e{var h,a,k,p=\"The Google Maps JavaScript API\",c=\"google\",l=\"importLibrary\",q=\"__ib__\",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=\u003eh||(h=new Promise(async(f,n)=\u003e{await (a=m.createElement(\"script\"));e.set(\"libraries\",[...r]+\"\");for(k in g)e.set(k.replace(/[A-Z]/g,t=\u003e\"_\"+t[0].toLowerCase()),g[k]);e.set(\"callback\",c+\".maps.\"+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=\u003eh=n(Error(p+\" could not load.\"));a.nonce=m.querySelector(\"script[nonce]\")?.nonce||\"\";m.head.append(a)}));d[l]?console.warn(p+\" only loads once. Ignoring:\",g):d[l]=(f,...n)=\u003er.add(f)&&u().then(()=\u003ed[l](f,...n))})\n ({key: \"AIzaSyA6myHzS10YXdcazAFalmXvDkrYCp5cLc8\", v: \"weekly\"});\u003c/script\u003e\n \u003c/body\u003e\n\u003c/html\u003ehttps://github.com/googlemaps-samples/js-api-samples/blob/cca4025329cd07519d74fb31e5f718e5365f32af/dist/samples/advanced-markers-html-simple/docs/index.html#L8-L22\n```\n\nTry Sample \n[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps-samples/js-api-samples/tree/main/dist/samples/advanced-markers-html-simple/jsfiddle)\n\nClone Sample\n\n\nGit and Node.js are required to run this sample locally. Follow these [instructions](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm) to install Node.js and NPM. The following commands clone, install dependencies and start the sample application. \n\n git clone https://github.com/googlemaps-samples/js-api-samples.git\n cd samples/advanced-markers-html-simple\n npm i\n npm start"]]