Back to Snippets

Modern Contact Form with Map JS

A two column contact block with the form on one side and a live map on the other, plus an address and phone card sitting over the map.

The map is Leaflet with OpenStreetMap tiles, which needs no API key and no billing account. The marker uses a custom icon, and its anchor is set to the bottom center of the image so the point of the pin lands on the coordinates rather than the middle of the graphic.

Change the latitude and longitude in the setView call to move the map, and keep the OpenStreetMap attribution, since their tile usage policy requires it. The form is markup only with no submit handler, so point it at your own endpoint. Leaflet loads from a CDN and setup runs behind a short timeout to wait for it, which you can drop once the library is part of your own build.

200
#javascript
#css
#html
#contact form
#map
#openstreetmap
#leaflet
#ui
#responsive