Skip to content

Weather Card with Forecast

Sky-blue weather card with a CSS-drawn sun and clouds, current conditions, quick stats, a 5-day forecast with range bars and a Celsius/Fahrenheit switch.

Also known as: weather widget, 5 day forecast card, temperature unit switch, weather app card

Weather Card with Forecast live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A sky-blue weather card in pure CSS and vanilla JavaScript, with a CSS-drawn sun and drifting clouds, the current temperature, three quick stats and a five-day forecast with range bars. A small switch converts every value between Celsius and Fahrenheit. Use it in dashboards, travel sites, smart-home panels or as a sidebar widget.

How it works

The root article.wc-card starts with a hidden svg.wc-sprite that defines four icon symbols (#wc-i-sun, #wc-i-cloud, #wc-i-partly, #wc-i-rain), reused in the forecast with <use>. The .wc-head shows the city, the time and the .wc-units button group. In .wc-now, the .wc-hero illustration is drawn entirely with CSS: .wc-sun is a radial gradient that softly pulses with the wc-glow keyframes, and each .wc-cloud is a pill whose ::before and ::after circles form the puffs, drifting with wc-drift. Next to it .wc-temp, .wc-cond and .wc-feels show the reading. The dl.wc-stats grid holds humidity, wind and UV, and .wc-forecast lists the days as .wc-day rows.

Every temperature is a span with the Celsius value in data-wc-c, and the wind speed uses data-wc-kmh. On DOMContentLoaded the script initializes every .wc-card. A click on a .wc-unit button converts all those values, swaps "km/h" for "mph", updates aria-pressed and stores the choice in data-wc-unit. It also reads data-wc-min and data-wc-max from each day, finds the weekly extremes and sets --wc-start and --wc-end on .wc-range-fill, so every bar sits on the same scale. Without JavaScript the card still shows Celsius values and full-width bars.

Customization

  • data-wc-unit on .wc-card: set to f to start in Fahrenheit.
  • data-wc-c on any temperature span and data-wc-kmh on the wind value: put your API data here (always in metric); the visible text is generated from them.
  • data-wc-min and data-wc-max on each .wc-day: the low and high that position its range bar.
  • --wc-sky-top and --wc-sky-bottom: the gradient of the card; try dark navy for a night variant.
  • --wc-cool and --wc-warm: the two ends of the range bar gradient.
  • --wc-drift: the cloud movement duration; larger values make it slower.
  • Swap the href of a <use> element, for example to #wc-i-rain, and update its aria-label to change a forecast icon.

Use cases

  • Travel sites: a card shows current conditions and a five-day forecast for a destination
  • Dashboards and smart-home panels: users switch all temperatures between Celsius and Fahrenheit
  • Sidebar widgets: humidity, wind and UV appear as quick stats beside a CSS-drawn sun and clouds
  • Event pages: range bars make the weekly highs and lows easy to compare at a glance

Accessibility

The card is an article labelled by the city heading, and the forecast is a labelled section with a list. The unit buttons form a role="group" named "Temperature unit" and expose their state with aria-pressed; a polite live region announces the new unit. Forecast icons have role="img" and an aria-label, while the decorative hero and range bars are aria-hidden. Buttons show a white :focus-visible outline. With prefers-reduced-motion: reduce the sun and clouds stop moving.

Usage notes

Fetch data from your weather API, fill the data attributes and call the same conversion logic. Several cards can share a page because each one is initialized separately.

Weather Card with Forecast at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile
Category
Weather Widgets
License
Free for personal and commercial use

Questions about this template

Can I use the Weather Card with Forecast code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Weather Card with Forecast – free Pure CSS weather widget template
Weather Card with Forecast · free Pure CSS weather widget template

More Weather Widgets

Weather Forecast with Weekly View – free Tailwind CSS weather widget template

Weather Forecast with Weekly View

Tailwind CSS weather widget with current conditions, a selectable 7-day forecast with temperature range bars, and a °C/°F switch.

Weather Card with City Photo Background – free Bootstrap 5 weather widget template

Weather Card with City Photo Background

Bootstrap 5 weather card over a city photo with a city switcher, Celsius/Fahrenheit toggle, current conditions and a 5-day forecast on frosted glass.