Skip to main content
Login

Sign in to access your account

Weather - National Design System

The current weather for one or more places, from their coordinates.

Overview

A .nds-weather element shows the current weather for one place. You write its markup, the place’s coordinates and, in .nds-weather-city, its name. The script fills three slots: the icon, the conditions and the temperature. It changes nothing else, so the layout, the order and the words around the slots are yours. A page can show any number of places. The Top Bar can show one as an item.

An element with no slots gets the auto line: the icon, the name, the conditions and the temperature with its unit, in the page language. The canon uses a Meta line, and the tile structure a Card.

Pick another component when:

  • the page shows today’s date: Date
  • the page shows the time: Clock

Markup

Preview
Riyadh · --, --°C
<span class="nds-meta"> <span class="nds-meta-item nds-weather" data-latitude="24.7136" data-longitude="46.6753"> <i class="nds-icon nds-weather-icon" aria-hidden="true"></i> <span><span class="nds-weather-city">Riyadh</span> · <span class="nds-weather-condition">--</span>, <span class="nds-weather-temp">--</span>°C</span> </span> </span>

Built-in Features

  • Open-Meteo

    The weather comes from the public Open-Meteo service, with no key and no account. It renders again every 15 minutes while the tab shows.

  • Day and Night

    The icon shows day or night at the place itself, as Open-Meteo reports it, not at the visitor's clock.

  • One Request per Place

    Elements on the same place and unit share one request. The browser keeps each result for 14 minutes, so a page load or a language switch in that time sends no request.

Best Practices

  • Set data-latitude and data-longitude to the place your service is for. The Riyadh default is wrong for a service in another region.
  • Write the place’s name in .nds-weather-city, so people know which place the weather is for. Without it, the element shows only the conditions and the temperature.
  • Write a placeholder, such as --, in each text slot. It holds the line’s width until the weather arrives.
  • Write the unit after .nds-weather-temp, to match data-weather-unit: the script writes the number only.
  • Your own words around the slots stay in one language. Where one markup serves every language, use the auto line, or mark your words with data-i18n.
  • Where one markup serves every language, mark the name with data-i18n. Give its other languages in window.NDS_I18N_LANGS, as for any word of your own. See Internationalization. A page per language needs neither: write the name in that page’s language.
  • Show a few places at most. Each place is one request from each visitor, at most once every 14 minutes.
  • In the top bar, the weather is one of the two items DGA allows.

API

Classes

Class Element Effect
.nds-weather Any element, such as a span.nds-meta-item or a .nds-card The item. The script fills its slots and changes nothing else. With no slot, it writes the auto line
.nds-weather-icon An i.nds-icon in .nds-weather Slot. The script adds the icon class for the conditions, by day or night
.nds-weather-condition A span in .nds-weather Slot. The script writes the conditions, such as “Clear”, in the page language
.nds-weather-temp A span in .nds-weather Slot. The script writes the temperature as a whole number, in the unit data-weather-unit picks, with no unit sign
.nds-weather-city A span in .nds-weather Optional. The place’s name, as the page’s own text. The script never writes it

Data Attributes

Attribute Element Effect
data-latitude, data-longitude .nds-weather The place’s coordinates. The default is Riyadh (24.7136, 46.6753)
data-weather-unit .nds-weather c (the default) for Celsius, f for Fahrenheit. The weather service sends the temperature in that unit, and the auto line writes its sign
hidden .nds-weather The script sets it when the request fails, and removes it when a request works

The words come from the weather section of the string pack: the conditions, and the auto line with or without the place’s name. A change of lang on <html> writes every item again, from the cache.

JavaScript

NDS.Weather loads after the page shows. Until it loads, a call to it loads it and returns a promise.

Method Effect
NDS.Weather.init() Writes every item on the page, from the cache or a new request. Renders them again every 15 minutes. The loader runs it when an item is on the page. NDS.init.mount() runs it on markup added later
// Add a place after load, then let NDS fill it const item = document.createElement('span'); item.className = 'nds-meta-item nds-weather'; Object.assign(item.dataset, { latitude: '26.4207', longitude: '50.0888' }); item.innerHTML = '<i class="nds-icon nds-weather-icon" aria-hidden="true"></i> <span><span class="nds-weather-city">Dammam</span> · <span class="nds-weather-condition">--</span>, <span class="nds-weather-temp">--</span>°C</span>'; document.querySelector('#branch-weather').append(item); NDS.init.mount(item);

The full API is in the banner of _js/nds-weather.js.

Last Modified Date: 02/11/2026 - 03:47 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks