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
Condition
Icon
Background 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.
2. Add the script in Footer code
(function() { var el = document.getElementById('weather-widget'); if (!el) return;
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)'); } })();
good to know
The Open-Meteo API is free and doesn’t require an API key for reasonable use. Geolocation triggers a browser permission prompt, so plan a default state if the user declines it (the script shows Dubai at 22°C as a fallback). On slow connections, the gray “Cloudy” background appears while the content loads.
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
Good to know
Heading
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.