Air quality is becoming a critical health concern worldwide. Whether you're building a weather app, a health tracker, or a smart home dashboard — real-time air quality data makes your app more valuable.
In this tutorial, I'll show you how to build a live air quality dashboard using vanilla JavaScript and the Air Quality Index API on RapidAPI.
What We're Building
A dashboard that shows:
- Current AQI (Air Quality Index) for any city
- Pollutant breakdown (PM2.5, PM10, O3, NO2, SO2, CO)
- Health recommendations based on current conditions
- Color-coded risk levels (Good → Hazardous)
Prerequisites
- Basic JavaScript knowledge
- A free RapidAPI account (sign up here)
- A text editor and browser
Step 1: Get Your API Key (1 minute)
- Go to the Air Quality Index API on RapidAPI
- Click Subscribe to Test and select the Free plan (100 requests/day)
- Copy your
X-RapidAPI-Keyfrom the code snippets section
Step 2: Build the HTML (5 minutes)
Create an index.html file:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Air Quality Dashboard</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #f0f2f5; padding: 2rem;
}
.dashboard {
max-width: 600px; margin: 0 auto;
}
h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.5rem; }
.search {
display: flex; gap: 8px; margin-bottom: 1.5rem;
}
.search input {
flex: 1; padding: 10px 14px; border: 1px solid #ddd;
border-radius: 8px; font-size: 1rem;
}
.search button {
padding: 10px 20px; background: #2563eb; color: white;
border: none; border-radius: 8px; font-size: 1rem; cursor: pointer;
}
.search button:hover { background: #1d4ed8; }
.aqi-card {
background: white; border-radius: 12px; padding: 2rem;
box-shadow: 0 2px 10px rgba(0,0,0,0.1); text-align: center;
margin-bottom: 1.5rem;
}
.aqi-value {
font-size: 4rem; font-weight: 800; line-height: 1;
}
.aqi-label {
font-size: 1.25rem; font-weight: 600; margin-top: 0.5rem;
}
.aqi-advice {
color: #666; margin-top: 0.75rem; font-size: 0.95rem;
line-height: 1.4;
}
.pollutants {
display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
.pollutant {
background: white; border-radius: 10px; padding: 1rem;
box-shadow: 0 1px 4px rgba(0,0,0,0.08); text-align: center;
}
.pollutant .name { font-size: 0.75rem; color: #999; text-transform: uppercase; }
.pollutant .value { font-size: 1.5rem; font-weight: 700; margin: 4px 0; }
.pollutant .unit { font-size: 0.7rem; color: #999; }
.hidden { display: none; }
</style>
</head>
<body>
<div class="dashboard">
<h1>Air Quality Dashboard</h1>
<div class="search">
<input type="text" id="city" placeholder="Enter city name..." value="London">
<button id="searchBtn">Check AQI</button>
</div>
<div id="results" class="hidden">
<div class="aqi-card" id="aqiCard">
<div class="aqi-value" id="aqiValue">--</div>
<div class="aqi-label" id="aqiLabel"></div>
<div class="aqi-advice" id="aqiAdvice"></div>
</div>
<div class="pollutants" id="pollutants"></div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>

Top comments (0)