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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

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.

              <div class="spinner load">

<main class="container">
  <h1>Free C<span id="icon"></span>de Camp</h1>
  <h2>Weather Forecast</h2>
  <div id="city"></div>
  <div class="temp">
    <span id="temp"></span><span id="metric"></span>
  <div id="weatherType"></div>

  <div class="search">
    <label for="city-search">Find a forecast</label>
    <input type="text" id="city-search" placeholder="e.g. New York, NY" autofocus><br>

  <a href='' target='_blank'>By <span>Simon</span></a>

<script src=",geometry">
              * {
  margin: 0;
  padding: 0;

body {
  font-family: "Skranji", cursive;
  font-size: calc(18px + 0.1vw);
  line-height: calc(3em + 0.1vh);
  text-shadow: 0.6px 0.6px 1px #fff;
  background-size: cover;
  background-position: center;
  min-height: 100vh;

.load {
  position: fixed;
  width: 100%;
  height: 100%;
  z-index: 9999;
  background: #fff
    no-repeat center center;

.container {
  max-width: 700px;
  margin: 0 auto;
  text-align: center;

h1 {
  font-size: 2.2em;
  word-spacing: 0.1em;

h2 {
  font-weight: 100;
  margin-top: -0.5em;
  letter-spacing: 0.025em;
  word-spacing: 0.05em;

span#icon {
  position: relative;
  top: 0.2em;

span#metric {
  color: #1e88e5;
  font-weight: bold;
  text-shadow: 0.8px 0.2px 0.1px #000;  

#metric:hover {
  cursor: pointer;
  font-size: 1.1em;

.temp {
  margin-top: 1.5em;

#city {
  margin-top: 1.5em;

#weatherType {
  margin-top: 1.5em;

.search {
  margin-top: 1.5em;

input[type="text"] {
  font-size: 0.8em;
  width: 14em;
  line-height: 1.6em;
  border: none;
  border-radius: 5px;
  box-shadow: 0 0 15px 1px #1e88e5;
  transition: all 0.3s;

input[type="text"]:focus {
  outline: none;
  box-shadow: 3px 3px 30px 4px #1e88e5;

footer {
  margin-top: 3em;
  text-align: center;

footer a {
  text-decoration: none;
  color: #000;

footer a:hover {
  text-decoration: underline;

footer span:hover {
  color: #1e88e5;

              // locating you
if (navigator.geolocation) {
  navigator.geolocation.getCurrentPosition(function(position) {
    let lat = position.coords.latitude;
    let lon = position.coords.longitude;
    getWeather(lat, lon);
} else {
  alert("Sorry, Geolocation is not supported by this browser.");

// getting the weather data using fetch()
function getWeather(lat, lon) {
  let api =
    .then(blob => blob.json())
    .then(data => {
      let cTemp = data.main.temp;
      let city =;
      let country =;
      let weatherType =[0].main;
      let weatherDesc =[0].description;
      let icon =[0].icon;
      querySelector("#city").innerHTML = city + ", " + country;
      querySelector("#weatherType").innerHTML =
        weatherType + " (" + weatherDesc + ")";
      querySelector("#icon").innerHTML =
        "<img alt='o' src=" + icon + ">";
      let fTemp = (cTemp * 9 / 5 + 32).toFixed(1);
      let toggleCF = false;
      let temp = querySelector("#temp");
      let metric = querySelector("#metric");
      temp.innerHTML = cTemp;
      metric.innerHTML =  " &#8451;";
      metric.addEventListener("click", function() {
      if (toggleCF === false) {
        temp.innerHTML = fTemp;
        metric.innerHTML = " &#8457;";
        toggleCF = true;
      } else {
        temp.innerHTML = cTemp;
        metric.innerHTML = " &#8451;";
       toggleCF = false;
    // console.log(weatherType);
    switch(weatherType) {
      case "Clear":
        querySelector("body").style["background-image"] = "url(,format&fit=crop&w=1477&h=&q=80&cs=tinysrgb&crop=)";
      case "Clouds": 
        querySelector("body").style["background-image"] = "url(,format&fit=crop&w=751&h=&q=80&cs=tinysrgb&crop=)";
      case "Rain":
        querySelector("body").style["background-image"] = "url(,format&fit=crop&w=750&h=&q=80&cs=tinysrgb&crop=)";
      case "Mist":
        querySelector("body").style["background-image"] = "url(,format&fit=crop&w=1508&h=&q=80&cs=tinysrgb&crop=)";
      case "Fog":
        querySelector("body").style["background-image"] = "url(,format&fit=crop&w=1570&h=&q=80&cs=tinysrgb&crop=)";
      case "Thunderstorm":
        querySelector("body").style["background-image"] = "url(,format&fit=crop&w=1489&h=&q=80&cs=tinysrgb&crop=)";
      case "Snow":
        querySelector("body").style['background-image'] = 'url(,format&fit=crop&w=1366&h=&q=80&cs=tinysrgb&crop=)';
        querySelector("body").style["background-image"] = "url(,format&fit=crop&w=750&h=&q=80&cs=tinysrgb&crop=)";
    .catch(err => alert(err));

// making easy to get elements from the DOM and interecting with HTML
function querySelector(element) {
  return document.querySelector(element);

// getting the weather for the searched city, -google api
let searchBox = new google.maps.places.Autocomplete(
searchBox.addListener("place_changed", function() {
  let locale = searchBox.getPlace();
  let lat =;
  let lon = locale.geometry.location.lng();
  getWeather(lat, lon);

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.