Skip to content

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.

Also known as: weather widget, city weather card, weather forecast card, 5 day forecast widget, temperature widget

Weather Card with City Photo Background live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A Bootstrap 5 weather card laid over a full-bleed photo of the selected city, with a city switcher, a Celsius/Fahrenheit toggle, current conditions, three key stats and a 5-day forecast on a frosted glass panel. Use it on travel sites, city guides or dashboards.

How it works

The card is article.card.wc-card inside the .wc-wrap demo wrapper. .wc-photos stacks one img.wc-photo per city, each tagged with data-city; only the photo with .is-active is visible, and switching cities crossfades the opacity while the new photo eases out of a slight zoom. A gradient in .wc-card::after darkens the top and bottom so white text stays readable on any photo.

.wc-content sits above the photos. The top row holds two .wc-seg pill groups built from Bootstrap btn-check radio inputs: the cities and the temperature unit. The bottom row is a Bootstrap row: .wc-now shows the place, local time, big temperature, condition icon and high/low; .wc-glass uses backdrop-filter for the frosted panel with the dl.wc-stats (feels like, humidity, wind) and the ul.wc-days forecast.

All values come from the CITIES object in script.js, stored in Celsius and km/h. On DOMContentLoaded the script initialises every .wc-wrap, makes the radio names and ids unique per card, and listens for change on both radio groups. render() fills every element with a data-wc attribute, swaps the condition icon class, rebuilds the forecast list, converts to Fahrenheit and mph when °F is selected, and moves .is-active to the matching photo. The markup ships with the Paris values.

Customization

  • CITIES in script.js: add a city (key, place, time, values and five forecast days), then add a matching radio input and an img.wc-photo with the same data-city value.
  • --wc-accent on .wc-wrap in style.css: changes the color of the weather icons and the location pin.
  • --wc-shade: adjust the photo overlay gradient; make it darker for bright photos.
  • --wc-glass and --wc-glass-border: change the transparency of the frosted stats panel.
  • --wc-radius: corner radius of the card (default 1.75rem).
  • checked on #wc-unit-f: start in Fahrenheit for a US audience.
  • min-height: 480px in .wc-card and .wc-content: make the card taller to show more of the photo.

Use cases

  • Travel sites: visitors switch between city photos and see current conditions before booking
  • City guides: a frosted glass card shows weather over a photo of each destination
  • Dashboards: compact weather block with feels like, humidity and wind plus a 5-day forecast
  • Hotel and tourism pages: let guests check the local time and forecast for the destination
  • International audiences: a Celsius and Fahrenheit toggle serves both metric and US visitors

Accessibility

Both pill groups are radiogroup elements with an aria-label and native radio inputs, so arrow keys switch cities and units, and the focused pill gets a yellow outline. A visually hidden role="status" region announces the new city, temperature and condition after each change. Inactive photos get aria-hidden="true" so only the current city's alt text is read. Forecast icons are hidden from screen readers and replaced by visually hidden labels such as "Rain,". The photo transition is turned off with prefers-reduced-motion.

Usage notes

Requires Bootstrap 5 (added automatically) and Bootstrap Icons. The weather data is static sample data; fill CITIES from a fetch() call to your weather API before the first render(). .wc-wrap uses min-height: 100vh for the demo; remove it when embedding the card. The city photos come from Unsplash; replace them with your own images.

Weather Card with City Photo Background at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
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 City Photo Background 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?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). 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

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Weather Card with City Photo Background – Bootstrap 5 weather widgets component screenshot
Weather Card with City Photo Background · Bootstrap 5 Weather Widgets

More Weather Widgets

Weather Forecast with Weekly View – Tailwind CSS weather widgets preview

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 Forecast – Pure CSS weather widgets preview

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.