Skip to content

Easter egg4 min read

How to Display Local Weather with an Adaptive Background in Webflow

Learn how to display a visitor’s local weather with a background that adapts to the weather conditions in Webflow.

In this tutorial, Sandro, cofounder of the Gemeos Webflow agency, shows you how to display the visitor’s local weather with a background that adapts to the weather conditions in Webflow.

Example

Allow geolocation to see your weather — or simulate a condition

ConditionIconBackground gradient
Sunny☀️Gold to orange
Cloudy⛅Blue-gray
Rainy🌧️Deep blue
Snowy❄️Pale light blue
Stormy⛈️Dark charcoal
Foggy🌫️Light gray

1. Create the container in Webflow

Create a Div with the ID weather-widget. The script injects the content and style automatically, gradient background, icon, temperature, and all. You can place the Div anywhere on your page.

(function() {
  var el = document.getElementById('weather-widget');
  if (!el) return;

  var weatherConfig = {
    sunny:  { icon: '☀️', label: 'Sunny',    bg: 'linear-gradient(135deg,#ffd700,#ff8c00)', color: '#111' },
    cloudy: { icon: '⛅', label: 'Cloudy',        bg: 'linear-gradient(135deg,#b0bec5,#78909c)', color: '#fff' },
    rainy:  { icon: '🌧️', label: 'Rainy',       bg: 'linear-gradient(135deg,#4169e1,#1e3a8a)', color: '#fff' },
    snowy:  { icon: '❄️', label: 'Snowy',         bg: 'linear-gradient(135deg,#e3f2fd,#90caf9)', color: '#111' },
    stormy: { icon: '⛈️', label: 'Stormy',        bg: 'linear-gradient(135deg,#37474f,#1a1a2e)', color: '#fff' },
    foggy:  { icon: '🌫️', label: 'Foggy',        bg: 'linear-gradient(135deg,#cfd8dc,#90a4ae)', color: '#111' },
  };

  function getCondition(code) {
    if (code === 0) return 'sunny';
    if (code <= 3) return 'cloudy';
    if (code <= 48) return 'foggy';
    if (code <= 67) return 'rainy';
    if (code <= 77) return 'snowy';
    return 'stormy';
  }

  function render(condition, temp, city) {
    var cfg = weatherConfig[condition] || weatherConfig.sunny;
    el.style.cssText = 'background:' + cfg.bg + ';border-radius:16px;padding:1.5rem;' +
      'display:flex;align-items:center;gap:1rem;transition:all 0.5s;';
    el.innerHTML = '' + cfg.icon + '' +
      '<div><p style="font-size:20px;font-weight:500;color:">' +
      temp + '°C — ' + cfg.label + '</p>' +
      '<p style="font-size:13px;color:">' + (city || 'Your location') + '</p></div>';
  }

  render('cloudy', '...', 'Location in progress...');

  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(function(pos) {
      var lat = pos.coords.latitude, lon = pos.coords.longitude;
      fetch('https://api.open-meteo.com/v1/forecast?latitude=' + lat + '&longitude=' + lon + '¤t_weather=true&timezone=auto')
        .then(function(r) { return r.json(); })
        .then(function(d) {
          var w = d.current_weather;
          render(getCondition(w.weathercode), Math.round(w.temperature), 'Your location');
        });
    }, function() {
      render('sunny', '22', 'Dubai (demo)');
    });
  } else {
    render('sunny', '22', 'Dubai (demo)');
  }
})();

Conclusion

A weather widget with an adaptive background creates a contextual experience. Use cases:

  • Homepage sections for lifestyle or travel websites
  • SaaS apps with contextual personalization
  • Local websites that want to show their territorial roots

Allow geolocation to see your weather

Published on May 20, 2026

Sandro DA SILVA

Growth Marketer, Webflow expert, and jack-of-all-trades. Sandro handles commercial operations, ensures projects run smoothly, and addresses marketing-related issues (SEO, Tracking, Copywriting, etc).

You're going to working with us, guaranteed

Ready to launch your business?

get a quote

Let’s f*****G GO !!