Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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.


Save Automatically?

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="wrapper">
  <h1>HTML5 Geolocation Demo</h1>
  <div id="status"></div>
  <button id="trigger">Show my location</button>

  <div class="results">
    <div class="result">
      <div id="accuracy"></div>
    <div class="result">
      <label>Altitude Accuracy</label>
      <div id="altitudeAccuracy"></div>
    <div class="result">
      <div id="latitude"></div>
    <div class="result">
      <div id="longitude"></div>
    <div class="result">
      <div id="heading"></div>
    <div class="result">
      <div id="speed"></div>
    <div class="result">
      <div id="altitude"></div>
  <small>Learn more about the HTML5 Geolocation API with this <a href="">comprehensive guide</a>.</small>


                * {
  box-sizing: border-box;

body {
  color: #03121b;
  font-family: 'Literata', serif;
  font-size: 18px;
  font-weight: normal;
  line-height: 1.5;
  padding: 1rem;

h1 {
  margin-bottom: 2rem;

#status {
  font-family: 'Rubik', sans-serif;

label {
  color: #254959;
  display: block;
  font-size: 0.85rem;
  margin-bottom: 0.2rem;

a {
  color: #20baff;
  text-decoration: none;
  &:hover {
    text-decoration: underline;

button {
  background: #20baff;
  border: 0;
  border-radius: 0.3em;
  color: #fff;
  cursor: pointer;
  font-family: 'Literata', serif;
  font-weight: 500;
  outline: none;
  padding: 1.5rem;
  transition: all 0.5s;
  width: 100%;
  &:hover {
    background: #03121b;

small {
  display: block;
  margin-top: 1.5rem;

.wrapper {
  margin: auto;
  max-width: 860px;
  width: 100%;

.results {
  display: flex;
  flex-wrap: wrap;
  margin-left: -0.25rem;
  margin-right: -0.25rem;
  margin-top: 0.5rem;

.result {
  background: hsla(0,0%,89.4%,0.5);
  display: none;
  margin-bottom: 0.5rem;
  margin-left: 0.25rem;
  margin-right: 0.25rem;
  padding: 1rem;
  width: calc(100% / 3 - 0.5rem);
  div {
    font-size: 1.4rem;

#status {
  background: #f5d67b;
  bottom: 0;
  display: none;
  font-size: 0.9rem;
  max-width: 450px;
  padding: 1.5rem;
  position: absolute;
  right: 0;


                const geolocate = function () {
  const $status = $("#status");
  const $latitude = $("#latitude");
  const $longitude = $("#longitude");
  const $heading = $("#heading");
  const $speed = $("#speed");
  const $altitude = $("#altitude");
  const $accuracy = $("#accuracy");
  const $altitudeAccuracy = $("#altitudeAccuracy");
  const $result = $(".result");
  const $trigger = $("#trigger");

  const success = (position) => {
    const latitude = position.coords.latitude;
    const longitude = position.coords.longitude;
    const speed = position.coords.speed ? position.coords.speed : "N/A";
    const heading = position.coords.heading ? position.coords.heading : "N/A";
    const altitude = position.coords.altitude
      ? position.coords.altitude
      : "N/A";
    const accuracy = (position.coords.accuracy / 1609).toFixed(3);
    const altitudeAccuracy = (position.coords.altitudeAccuracy / 1609).toFixed(3);

    $latitude.html(latitude + "&deg;");
    $longitude.html(longitude + "&deg;");
    $accuracy.html(accuracy + " mile" + (accuracy > 1 ? "s" : ""));
    $altitudeAccuracy.html(altitudeAccuracy + " mile" + (altitudeAccuracy > 1 ? "s" : ""));

    $trigger.html("Refresh location");


  const error = () => {
    $status.html('Unable to retrieve your location. This may be due to your browser security settings or a known Chrome issue with embedded iframes, <a href="" target="_blank"><strong>try it directly on CodePen</strong></a>.').show();
    $trigger.html("Try directly on CodePen").click(function( e ) {
      e.preventDefault(); '', '_blank' );

  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(success, error);
  } else {
    $trigger.html("Not supported.");
    $status.html("Geolocation is not supported by your browser.").show();;

$("#trigger").click(() => {