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 is required to process package imports. If you need a different preprocessor remove all packages first.

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


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.


  <h1 id= "city">Weather Web App</h1>
  <p> <a id="temperature" href="#" onclick="switchUnits(); return false;" title ="Click to switch between metric and impreial units"></a><span id = "weather"> by Shazam (tutorial from @fourtonfish)</p>

  <p>Powered by <a href="">Flickr</a> and <a href=""></a>.
  Created by <a href="">@steelcitycoach</a>. <a id="image-source" href="#">Image source</a>.</p>



                body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family:Arial, sans-serif;
  font-size: 2em;
  text-shadow: 0 0 10px #000;
  color: #fff;
  background: #888;
  bacground-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;

section {

   min-height: 100%;

h1 {
    font-size: 2em;
  padding: 0 0.3em;
  line-height: 1em;

p {
  padding: 0 1em;

  color: #fff;

footer {
  position: absolute;
  bottom: 0;
  font-size: 0.5em;

#temperature {
   text-decoration: none;
  border-bottom: 0.05em dotted white;




var weatherData = {
  city: document.querySelector ("#city"),
  weather: document.querySelector ("#weather"),
  temperature: document.querySelector("#temperature"),
  temperatureValue: 0,
  units: "°C"

function roundTemperature(temperature){
			temperature = temperature.toFixed(1);
			return temperature;

function switchUnits (){
  if (weatherData.units == "°C") {
    weatherData.temperatureValue = roundTemperature(weatherData.temperatureValue * 9/5 + 32);
    weatherData.units = "°F";
} else {
  weatherData.temperatureValue = roundTemperature ((weatherData.temperatureValue -32) * 5/9);
    weatherData.units = "°C";  

  weatherData.temperature.innerHTML = weatherData.temperatureValue + weatherData.units + " ";

function getLocationAndWeather(){
  if (window.XMLHttpRequest){
    var xhr = new XMLHttpRequest();
    xhr.addEventListener("load", function() {
      var response = JSON.parse(xhr.responseText);

      var position = {
        latitude: response.latitude,
        longitude: response.longitude
      var cityName =;

      var weatherSimpleDescription =;
      var weatherDescription =;
      var weatherTemperature = roundTemperature(;

      weatherData.temperatureValue = weatherTemperature;

      loadBackground(position.latitude, position.longitude, weatherSimpleDescription); = cityName; =  ", " + weatherDescription;
      weatherData.temperature.innerHTML = weatherTemperature + weatherData.units;
    }, false);

    xhr.addEventListener("error", function(err){
      alert("Could not complete the request");
    }, false);"GET", "", true);
    alert("Unable to fetch the location and weather data.");

function loadBackground(lat, lon, weatherTag) {
  var script_element = document.createElement('script');

  script_element.src = "" + lat + "&lon=" + lon + "&accuracy=1&tags=" + weatherTag + "&sort=relevance&extras=url_l&format=json";

function jsonFlickrApi(data){
  if ( > 0){
    //var randomPhotoId = parseInt(;
    var photo =[Math.floor(Math.random()*parseInt(];
    document.querySelector("body").style.backgroundImage = "url('" + photo.url_l + "')";
    document.querySelector("#image-source").setAttribute("href", "" + photo.owner + "/" +;
    document.querySelector("body").style.backgroundImage = "url('')";
    document.querySelector("#image-source").setAttribute("href", "");