The KML file format (Keyhole Markup Language) is an XML-based standard for expressing geographic annotation and visualization. KML files describe points, lines, polygons, 3D models, and imagery overlays that can be displayed in geospatial viewers such as Google Earth and Google Maps. Adopted as an Open Geospatial Consortium (OGC) standard in 2008, KML remains one of the most widely supported formats for sharing styled geographic data with both technical and non-technical audiences.
History: From Keyhole Inc to Google
KML originated at Keyhole, Inc., a startup founded in 2001 that built the 3D globe viewer eventually known as Google Earth. The name "Keyhole Markup Language" reflects this heritage. Google acquired Keyhole in 2004, rebranded the viewer, and opened the KML specification so that any application could read and write the format. In 2008, KML 2.2 was adopted as an official OGC standard (OGC KML 2.2), ensuring long-term interoperability across GIS software, web services, and mobile applications.
This trajectory — from a proprietary visualization format to an open standard — explains why KML is simultaneously associated with Google Earth and supported by tools like QGIS, ArcGIS, and GeoDataTools. Understanding this history helps clarify KML's design priorities: rich visual presentation and ease of use over raw data analysis.
XML Structure of a KML File
Every KML file begins with a standard XML declaration and a root <kml> element that references the KML namespace. Inside that root, you typically find a <Document> element that acts as a container for all other elements. The Document can hold metadata such as a name, description, and shared styles that child elements reference by ID.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>My Project</name>
<description>Sample KML with a point and polygon</description>
<Placemark>
<name>Empire State Building</name>
<Point>
<coordinates>-73.9857,40.7484,0</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Coordinates in KML are always expressed as longitude, latitude, altitude — the same order as GeoJSON but with an explicit altitude component. The altitude value is measured in meters above sea level by default, though you can switch to relative or clamped-to-ground modes using the <altitudeMode> element.
Key Elements: Placemark, Document, and Folder
Three elements form the organizational backbone of most KML files. A Placemark is the fundamental feature: it wraps a single geometry with a name, description, and optional styling. A Document groups related Placemarks and shared styles into a logical unit. A Folder provides hierarchical nesting within a Document, letting you organize features into collapsible groups — useful for complex datasets with dozens or hundreds of features.
- Placemark — Contains one geometry (Point, LineString, Polygon, etc.) plus metadata
- Document — Top-level container for Placemarks, Folders, shared styles, and schemas
- Folder — Groups Placemarks and other Folders for organizational hierarchy
- GroundOverlay — Drapes an image over the terrain surface
- NetworkLink — Loads remote KML from a URL for dynamic data
Geometry Types in KML
KML supports a comprehensive set of geometry types that cover most mapping scenarios. Point represents a single location and is the most common geometry for markers and placemarks. LineString connects an ordered sequence of coordinates to form a path — ideal for routes, trails, and boundaries. Polygon defines a closed area with an outer boundary and optional inner boundaries (holes), used for parcels, lakes, and administrative regions.
For more complex features, KML provides MultiGeometry, which bundles several geometries of any type into a single Placemark. There is also LinearRing, which defines a closed loop of coordinates and is used internally to describe polygon boundaries. Unlike GeoJSON, KML also supports Model, a 3D geometry type that references a COLLADA file for rendering textured 3D objects on the globe.
Styling Capabilities
One of KML's strongest advantages over formats like GeoJSON is its built-in styling system. You can define IconStyle to customize point markers with custom images, scale, and heading. LineStyle controls the color, width, and opacity of line features. PolyStyle sets the fill color and outline of polygons. These styles can be defined inline within a Placemark or shared across features through Style and StyleMap elements defined at the Document level.
<Style id="redLine">
<LineStyle>
<color>ff0000ff</color>
<width>3</width>
</LineStyle>
</Style>
<Placemark>
<name>Route A</name>
<styleUrl>#redLine</styleUrl>
<LineString>
<coordinates>-122.084,37.422,0 -122.085,37.423,0</coordinates>
</LineString>
</Placemark>
KML colors use an aabbggrr hex format (alpha, blue, green, red) — the reverse of the typical web CSS #rrggbbaa convention. This is a common source of confusion when converting styles manually. Note that when you convert KML to GeoJSON, styling information is not preserved because the GeoJSON specification does not define a styling mechanism.
KMZ Archives
A KMZ file is simply a ZIP archive containing a KML file (typically named doc.kml) along with any referenced resources such as custom icons, images, 3D models, and texture files. Using KMZ reduces file size through compression and bundles all dependencies into a single distributable file. Google Earth and most KML-compatible tools can open KMZ files directly.
KMZ is particularly useful when sharing styled maps that include custom marker icons or ground overlay images. Instead of hosting assets on a web server and referencing them by URL, you package everything into one file. Most GIS tools, including GeoDataTools, handle KMZ extraction and parsing automatically.
Common Use Cases
KML is used across a wide range of industries and workflows. Urban planners use KML to share proposed development boundaries with stakeholders through Google Earth. Environmental scientists distribute species observation data in KML for visualization on 3D globes. Tourism organizations publish trail maps and points of interest as KML or KMZ downloads. Real estate platforms export property boundaries in KML for review in Google Maps.
In the development world, KML is frequently encountered as an export format from GPS devices, Google My Maps, and legacy GIS applications. Developers often need to convert KML to GeoJSON for use in modern web mapping libraries like Leaflet or Mapbox GL JS, since those libraries expect JSON-based input rather than XML.
KML vs GeoJSON: A Brief Comparison
| Feature | KML | GeoJSON |
|---|---|---|
| Format basis | XML | JSON |
| Built-in styling | Yes (IconStyle, LineStyle, PolyStyle) | No |
| 3D support | Yes (altitude, models) | Limited (optional altitude) |
| File size | Larger (verbose XML) | Smaller (compact JSON) |
| Web library support | Requires parsing | Native in most libraries |
| OGC standard | Yes (OGC KML 2.2) | IETF standard (RFC 7946) |
For a deeper dive into this comparison, see our GeoJSON vs KML comparison guide. If you need to work with both formats, GeoDataTools supports drag-and-drop import and one-click conversion between KML and GeoJSON directly in the browser.
FAQ
What programs can open a KML file?
Google Earth, Google Maps, QGIS, ArcGIS, and browser-based tools like GeoDataTools all open KML files. Most modern GIS platforms include KML import support. For quick visualization without installing software, drag your KML file into GeoDataTools to see it on an interactive map instantly.
What is the difference between KML and KMZ?
KML is a plain-text XML file describing geographic features. KMZ is a ZIP-compressed archive that bundles a KML file with referenced resources such as icons, images, and 3D models. KMZ files are smaller and more portable, making them the preferred choice for distribution.
Can I convert KML to other geospatial formats?
Yes. KML can be converted to GeoJSON, Shapefile, GeoPackage, and other formats using tools like QGIS, ogr2ogr from the GDAL library, or browser-based converters like the KML to GeoJSON converter in GeoDataTools. Keep in mind that KML styling is not preserved during conversion to formats that lack styling support.