A reusable weather widget works best as an autonomous custom element, such as <weather-widget>, with a small public API for location, units, and forecast fields. Keep data loading and permission handling inside the component, but make styling and content customization deliberate: use documented CSS properties, parts, or slots rather than asking page authors to reach into private markup. Browser location should be optional, requested only after a user action, and paired with manual location entry.
Design the widget’s public API first
Decide what a page author can configure before writing the component. A compact API is easier to document and less likely to lock consumers into internal markup.
latitudeandlongitude: a fixed location, when the page already knows the coordinates.units: a documented choice such asmetricorimperial.fields: the forecast values the widget should display, such as temperature or precipitation.- A location-selection mode or button that lets the visitor explicitly request their location, without silently doing so on page load.
For example, a host page might write <weather-widget latitude="51.5072" longitude="-0.1276" units="metric" fields="temperature,precipitation"></weather-widget>. Treat those attributes as a public contract: define valid values, defaults, and what happens when an attribute changes. If the host supplies a fixed location, the component need not ask the visitor for location permission.
Register an autonomous custom element
An autonomous custom element extends HTMLElement and defines its own tag and behavior. It is a suitable portable form for a widget, unlike a customized built-in element that extends an existing HTML element. MDN describes custom elements, Shadow DOM, and templates and slots as Web Component technologies that can be combined; they are useful together, but none requires that every widget use all three. See MDN’s Web Components overview and custom element documentation.
#1 Best Overall
- COMPLETE WEATHER STATION: (1) Osprey Sensor Array with Rain Cup, and (1) Brilliant, Easy-to-Read LCD Color Display
- AUTHENTIC HYPER-LOCAL DATA: Monitor your actual home and backyard weather conditions with our wireless and Wi-Fi-enabled sensor array measuring wind speed/direction, temperature, humidity, rainfall, UV intensity, and solar radiation
- SMART HOME READY: Set up alerts, access your data remotely, and program your home based on weather conditions using IFTT, Google Home, Alexa, and more
- ENHANCED WIFI: Enables your station to transmit its data wirelessly to the world's largest personal weather station network (optional setting)
- JOIN THE COMMUNITY: Connect to Ambient Weather Network to customize your dashboard tiles, share hyperlocal weather conditions via social feeds and create your own forecasts (coming soon)
class WeatherWidget extends HTMLElement {
static observedAttributes = ["latitude", "longitude", "units", "fields"];
constructor() {
super();
this.attachShadow({ mode: "open" });
this.renderShell();
}
connectedCallback() {
this.loadIfConfigured();
}
attributeChangedCallback() {
if (this.isConnected) this.loadIfConfigured();
}
renderShell() {
const template = document.createElement("template");
template.innerHTML = `
<style>
:host { display: block; }
.card { padding: 1rem; border-radius: var(--weather-radius, .75rem); }
[part="status"] { color: var(--weather-muted, #555); }
</style>
<section class="card" aria-live="polite">
<h2>Weather</h2>
<p part="status">Waiting for a location.</p>
<div part="forecast"></div>
<slot name="footer"></slot>
</section>`;
this.shadowRoot.append(template.content.cloneNode(true));
}
async loadIfConfigured() {
// Validate configuration, request only displayed fields,
// then render mapped data and explicit status messages.
}
}
if (!customElements.get("weather-widget")) {
customElements.define("weather-widget", WeatherWidget);
}
The example deliberately leaves provider-specific request construction to the data layer: the API terms, endpoint, and required fields depend on the service chosen. The registration guard prevents an exception if the same bundle is evaluated more than once. In production, also avoid duplicate network requests when multiple observed attributes change in quick succession; validate inputs and cancel or ignore obsolete requests.
Choose Shadow DOM or light DOM deliberately
Shadow DOM attaches an encapsulated tree to the component. It reduces the chance that page CSS or JavaScript accidentally breaks internal markup, but it also means host styles cannot freely target internal elements. MDN explains the encapsulation model in its Shadow DOM guide.
| Choice | Useful when | Trade-off |
|---|---|---|
| Shadow DOM | You want internal styles and markup protected from unrelated page rules. | Theme and layout changes need explicit hooks such as CSS custom properties, exposed parts, or slots; integration can be less transparent to host-page tooling. |
| Light DOM | Host-page CSS, debugging, and direct composition should remain straightforward. | Page styles can unintentionally alter widget internals, so class names and CSS behavior need careful design. |
Neither choice is universally better. If you use Shadow DOM, document its supported customization points rather than promising unrestricted styling. For example, consumers can set a public property and target the exposed part:
Rank #2
- [Color LCD Screen Weather Station] Newentor temperature & humidity monitor with a large color LCD display shows essential home weather information at a glance: indoor/outdoor temperature & humidity, daily high/low records, customizable alerts, time/date, alarm clock & snooze, weather forecast, moon phase, and barometric pressure.
- [Two Power Modes & Adjustable Backlight] To enjoy a 24/7 continuous always-on vibrant display, simply connect this home weather station to a wall outlet using the included DC power adapter. When operating on battery power only (batteries not included), the digital thermometer automatically enters an eco-energy-saving mode, where the screen lights up for a quick 15-second glance before dimming. It is the perfect bedside or living room clock designed to fit your power preference.
- [3-channel Home Weather Stations Wireless Indoor Outdoor] Wireless temperature forecast station supports up to 3 remote sensors to monitor inside outside temperature & humidity of multiple locations. Package contains one remote sensor.
- [Wireless Forecast Station] The weather forecast station calculates the weather forecast for the next 12-24 hours, 7 to 10 days calibration ensures an accurate personal forecast for your location.
- [Wireless Weather Station with Atomic Time&Date] Atomic alarm clock weather station can be used not only as a wireless indoor outdoor thermometer but also as an atomic clock with dual alarms.
<weather-widget style="--weather-radius: 1rem; --weather-muted: #444">
<span slot="footer">Forecast provided for this location</span>
</weather-widget>
weather-widget::part(forecast) {
display: grid;
gap: .5rem;
}
Fetch only the weather fields the display uses
A forecast request needs a location and selected forecast variables. Open-Meteo’s forecast API specification documents latitude and longitude parameters and a selectable list of variables; its forecast documentation describes hourly JSON and says current conditions are based on 15-minute weather model data. That is model-derived current-condition data, not necessarily a live observation. Consult the forecast API documentation and API specification for the service’s current request syntax.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsKeep provider-specific code behind one function that accepts a validated location, units, and field list. Build the request using the provider’s documented parameter names, then map the response into the small data shape your view needs. Avoid storing or rendering the entire provider response as though it were your widget’s stable API.
async function getForecast({ latitude, longitude, units, fields, signal }) {
// Construct the provider URL from its current documentation.
// Include coordinates, requested fields, and units as required.
const response = await fetch(buildProviderUrl({ latitude, longitude, units, fields }), { signal });
if (!response.ok) throw new Error(`Weather request failed: ${response.status}`);
const raw = await response.json();
return mapForecastForWidget(raw, fields, units);
}
The component should request only what its current presentation uses. A temperature-only card does not need a large collection of hourly and daily variables. Smaller, explicit data requirements simplify rendering and make provider changes easier to contain.
Rank #3
- Allows you to monitor your home and backyard weather conditions with TFT color display
- Wireless all-in-one integrated sensor array measures wind speed/direction, temperature, humidity, rainfall, UV and solar radiation
- Supports both imperial and metric units of measure with calibration available
- Enhanced Wi-Fi connectability option that enables your station to transmit its data wirelessly to the world's largest personal weather station network
- Console power provided by 5V DC adapter (included), and sensor array requires 3 x AAA batteries (not included)
Offer manual location and request geolocation only on intent
Browser geolocation is available only in secure contexts such as HTTPS in supporting browsers, and requesting it prompts the user for permission. A widget should explain why it wants location before requesting it and provide a manual alternative. See MDN’s Geolocation API guide.
- Let the visitor enter or select a location, or select an explicit control such as Use my location.
- When they choose that control, call
navigator.geolocation.getCurrentPosition()and handle both its success and error callbacks. - On success, pass the returned coordinates through the same validation and forecast-loading path as a fixed location.
- On denial, timeout, unsupported browser, or insecure context, show a useful explanation and keep manual location available.
The Permissions API can report states such as granted, denied, or prompt, but it does not replace handling the result of the geolocation request. Permission state and context restrictions still need to be accounted for. See MDN’s Permissions API reference.
async function useMyLocation() {
if (!navigator.geolocation) {
showLocationMessage("Location is unavailable in this browser. Enter a location instead.");
return;
}
showLocationMessage("Requesting your location…");
navigator.geolocation.getCurrentPosition(
({ coords }) => loadForecast({
latitude: coords.latitude,
longitude: coords.longitude
}),
(error) => {
const message = error.code === error.PERMISSION_DENIED
? "Location permission was not granted. Enter a location instead."
: "Could not determine your location. Try entering it manually.";
showLocationMessage(message);
},
{ enableHighAccuracy: false, timeout: 10000, maximumAge: 300000 }
);
}
The timeout and cached-position options above are example application choices, not universal browser requirements. Explain clearly when coordinates are used, and do not make geolocation a hidden prerequisite for viewing the widget.
Rank #4
- Illuminated Indoor Outdoor Weather Station for Home with Large Colorful Display: The home weather station delivers large big numbers for weather forecast info, indoor outdoor temperature, atomic time, date, year and calendar day, which is super easy to read from afar.
- Indoor outdoor Thermometer Wireless with High/Low Temperature Alert: The digital weather station supports 3 outdoor sensors which helps to monitor temperature and humidity of multiple locations (one sensor included). With the high/low temperature alert function, the weather station clock keeps you informed about the changes of weather thermometer outdoor.
- WWVB Atomic Weather Station with Auto DST: Weather atomic clock with indoor/outdoor temp always keeps precise time and date by receiving the WWVB atomic signal. The self setting digital weather clock will automatically adjust to daylight saving time with auto DST feature, no more resetting twice a year.
- Personal Weather Forecast Station: This weather stations wireless indoor outdoor predicts the next 12-24 hours weather condition with a 7-day calibration through the pressure of your location which provides you a better outing experience.
- 5 Level Adjustable Backlight Brightness: The weather clock indoor outdoor temperature atomic with backlight dimmer function helps you avoid high-intensity light that disturb your sleep and easily check the weather situation during the day.
Represent loading, errors, and missing data in the interface
Weather data can fail independently of the component rendering. Give each outcome a visible, understandable state instead of leaving an empty card or a perpetual spinner.
- Loading: announce that the forecast is being retrieved and avoid presenting old values as current.
- Location denied or unavailable: explain that location was not obtained and offer manual entry.
- Network or provider error: say that the forecast could not be loaded and offer a retry where appropriate.
- No requested value: omit that value or mark it unavailable; do not display
null,undefined, or fabricated zeroes. - Stale data: if you intentionally retain a previous result, identify it as outdated rather than implying it is the latest forecast.
An aria-live region can make status changes available to assistive technology, as in the shell example. Ensure the status text is updated for permission outcomes and fetch failures, not just successful responses.
Check provider terms before deploying
Provider choice is not only a technical decision. Compare the service’s permitted use, credential requirements, current/hourly/daily fields, geographic coverage, update cadence, attribution rules, rate limits, and reliability using its current documentation and terms. Those details can differ by provider and deployment; do not assume that an endpoint usable during development is licensed or provisioned for a commercial site.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Open-Meteo’s API specification labels its free API for open-source developers and non-commercial use. That statement does not establish current pricing or answer every licensing question for a particular deployment. Review the provider’s current terms and commercial access requirements before shipping a commercial widget. The implementation should also display any attribution required by the chosen provider; where possible, reserve a visible slot or footer area for it.
Quick Recap
Keep the component maintainable
- Document attributes, accepted values, defaults, events, styling hooks, and slots as part of the widget API.
- Validate coordinates and field names before a request; fail visibly when configuration is invalid.
- Separate provider request and response mapping from presentation so provider changes do not spread through the component.
- When settings change, prevent an older in-flight response from overwriting the latest requested forecast.
- Test the fixed-location path separately from location permission flows, including denial and unavailable-location cases.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

