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>Weather App</h1>
  <section class="location">
    <p data-location></p>
  <section class="weather" data-current="celsius">
    <div class="weather-icon"></div>
    <div class="weather-temperature">
      <span class="weather-temperature-unit weather-temperature-avg" title="Average"></span>
      <span class="weather-temperature-unit weather-temperature-high" title="Max"></span>
      <span class="weather-temperature-unit weather-temperature-low" title="Min"></span>
    <button class="switch-unit" type="button" title="Switch unit">
      <i class="fa fa-refresh"></i>


                // Moods
$undef = #34495e
$rainy = #1f3a93
$clear = #89c4f4
$snowy = #ececec

// Elements sizes
$size-wrapper = 300px
$size-weather-box-primary = 180px
$size-weather-box-secondary = $size-weather-box-primary / 2

// Elements
  font-family 'Lato', 'Arial', sans-serif
  font-size 20px

  background-color $undef
  color #fff
  transition background-color 1000ms linear
h1, p
  text-align center
  height 1.2em
  margin 2px 0
  background none
  border none
  margin 0
  padding 0
  position absolute
  bottom 10px
  right 10px
// Components
    background-color $clear
    background-color rgba(200,200,200,.4)
    border-radius 6px
    box-shadow 0.2em 0.2em 0.2em #444
    margin 10px auto
    min-height $size-wrapper
    padding 5px 25px
    position relative
    @media screen and (min-width: ($size-wrapper * 1.5))
      max-width $size-wrapper
    display flex
    flex-direction column
    flex-wrap wrap
    height $size-weather-box-primary
    font-size 2em
    text-align center
    position relative
    line-height $size-weather-box-secondary
    height $size-weather-box-secondary
    width $size-weather-box-secondary
      content attr(title)
      font-size .3em
      position absolute
      top -2em
      font-size .6em
      vertical-align super

    font-size 2.5em
    line-height $size-weather-box-primary
    height $size-weather-box-primary
    width $size-weather-box-primary
  [data-current="celsius"] .weather-temperature-unit:after
    content '°C'
  [data-current="fahrenheit"] .weather-temperature-unit:after
    content '°F'


                var WeatherService = (function() {
  var serviceUrl = '';
  var forecastUrl = serviceUrl + '/forecast'
  var locationUrl = serviceUrl + '/geolookup/q/autoip.json';
  var locationCode, city;

  var fetchedLocation = (function fetchLocation() {
    return $.getJSON(locationUrl).then(function(res) {
      city =;
      locationCode = res.location.l;

  return function() {
    return {
      getWeather: function() {
        return $.when(fetchedLocation).then(function() {
          return $.getJSON(forecastUrl + locationCode + '.json');
      getCity: function() {
        return $.when(fetchedLocation).then(function() {
          return city;

$(function() {
  function currentUnit() {
    return $(".weather").attr("data-current");

  function switchToCurrentUnit() {
    var unit = currentUnit();
    $(".weather-temperature-avg, .weather-temperature-high, .weather-temperature-low").each(function() {

  $(".switch-unit").on("click", function() {
    var unit = currentUnit() === "celsius" ? "fahrenheit" : "celsius";
    $(".weather").attr("data-current", unit);


  WeatherService().getCity().then(function(city) {

  WeatherService().getWeather().then(function(response) {
    var forecast = response.forecast.simpleforecast.forecastday[0];

    var high = {
      celsius: Number.parseFloat(forecast.high.celsius),
      fahrenheit: Number.parseFloat(forecast.high.fahrenheit)

    var low = {
      celsius: Number.parseFloat(forecast.low.celsius),
      fahrenheit: Number.parseFloat(forecast.low.fahrenheit)

    var average = {
      celsius: (high.celsius + low.celsius) / 2,
      fahrenheit: (high.fahrenheit + low.fahrenheit) / 2
    var weatherClass = "weather-" + forecast.conditions.toLowerCase();

      celsius: average.celsius,
      fahrenheit: average.fahrenheit

      celsius: high.celsius,
      fahrenheit: high.fahrenheit

      celsius: low.celsius,
      fahrenheit: low.fahrenheit