Ever needed to add currency conversion to your app? Whether you're building an e-commerce platform, a travel app, or a finance dashboard — you'll need reliable exchange rates.
In this tutorial, I'll show you how to build a working currency converter in under 10 minutes using vanilla JavaScript and the Currency Exchange Rates API on RapidAPI.
What We're Building
A simple web-based currency converter that:
- Converts between 31 major currencies
- Shows real-time rates from the European Central Bank (ECB)
- Updates instantly when you change the amount or currency
Prerequisites
- Basic JavaScript knowledge
- A free RapidAPI account (sign up here)
- A text editor and browser
Step 1: Get Your API Key (1 minute)
- Head to the Currency Exchange Rates API on RapidAPI
- Click Subscribe to Test and select the Free plan (100 requests/day — plenty for development)
- Copy your
X-RapidAPI-Keyfrom the code snippets section
Step 2: Build the HTML (3 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>Currency Converter</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
display: flex; justify-content: center; align-items: center;
min-height: 100vh; background: #f0f2f5;
}
.converter {
background: white; padding: 2rem; border-radius: 12px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1); width: 400px;
}
h1 { font-size: 1.5rem; margin-bottom: 1.5rem; text-align: center; }
.field { margin-bottom: 1rem; }
label { display: block; font-size: 0.875rem; color: #666; margin-bottom: 4px; }
input, select {
width: 100%; padding: 10px 12px; border: 1px solid #ddd;
border-radius: 8px; font-size: 1rem;
}
.result {
text-align: center; padding: 1.5rem; background: #f8f9fa;
border-radius: 8px; margin-top: 1rem;
}
.result .amount { font-size: 2rem; font-weight: 700; color: #2563eb; }
.result .rate { font-size: 0.875rem; color: #666; margin-top: 4px; }
.swap-btn {
display: block; margin: 0.5rem auto; background: none;
border: 1px solid #ddd; border-radius: 50%; width: 36px;
height: 36px; cursor: pointer; font-size: 1.2rem;
}
.swap-btn:hover { background: #f0f2f5; }
</style>
</head>
<body>
<div class="converter">
<h1>💱 Currency Converter</h1>
<div class="field">
<label>Amount</label>
<input type="number" id="amount" value="100" min="0" step="0.01">
</div>
<div class="field">
<label>From</label>
<select id="fromCurrency"></select>
</div>
<button class="swap-btn" id="swap" title="Swap currencies">⇅</button>
<div class="field">
<label>To</label>
<select id="toCurrency"></select>
</div>
<div class="result">
<div class="amount" id="resultAmount">—</div>
<div class="rate" id="resultRate"></div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>

Top comments (0)