Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div class="container">

  <h1>Geolocation API demo</h1>

  <form class="form-horizontal">
    <div class="form-group">
      <button type="button" class="find-me btn btn-info btn-block">Find your location</button>

  <p class="not-on-https">Not on HTTPS :( Most browsers require HTTPS to run the Geolocation API.</p>
  <p class="no-geolocation-support">The Geolocation API isn't supported in this browser :(</p>

  <p class="coordinates">Latitude is <b class="latitude">00.000000°</b>, longitude is <b class="longitude">00.000000°</b>.</p>

  <div id="map">
    <div id="map-canvas"></div>




                .container {
  margin: 2rem auto;
  max-width: 50rem;
  text-align: center;

form {
  margin: 2.5rem auto;

.find-me.btn {
  font-family: inherit;

.coordinates {
  font-size: 1.5em;

.no-geolocation-support {
  display: none;

.coordinates {
  display: none;
  margin-bottom: 2.5rem;

.visible {
  display: block;

#map {
  margin: 0 auto;
  position: relative;

#map-canvas {
  height: 25rem;
  min-height: 25rem;
  width: 100%;



                $(document).ready(function($) {

  var $findMeBtn = $('.find-me');

  // Check if browser supports the Geolocation API
  if (!navigator.geolocation) {


  // Check if the page is accessed over HTTPS
  } else if (location.protocol !== 'https:') {

    // Check if top-level frame
    if ( === window.self) {

      // Reload the page over HTTPS
      location.href = 'https:' + window.location.href.substring(window.location.protocol.length);

    // If not top-level, display a message
      // Note: CodePen does not allow an `<iframe>` to reload the top-level frame (browser window). See about the `sandbox` attribute at
    } else {



  // Let's use the Geolocation API
  } else {

    $findMeBtn.on('click', function(e) {


      navigator.geolocation.getCurrentPosition(function(position) {

        // Get the location coordinates
        var lat = position.coords.latitude;
        var lng = position.coords.longitude;

        $('.latitude').text(lat.toFixed(6) + '°');
        $('.longitude').text(lng.toFixed(6) + '°');

        // Create a map and place a marker at the current location

        var mapLatLng = new google.maps.LatLng(lat, lng);

        var mapOptions = {
          zoom: 15,
          mapTypeControl: false,
          center: mapLatLng,

        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        var mapMarker = new google.maps.Marker({
          position: mapLatLng,
          map: map,
          title: 'Your browser/device places you here',

        // Re-center the map on user location when window/viewport resizes
        $(window).resize(function() {
          google.maps.event.trigger(map, 'resize');