Build a Searchable 99 Names of Allah (Asma ul Husna) Page in Vanilla JavaScript
A "99 Names of Allah" screen is one of the most common features in Muslim apps and websites. In this post we'll build one with plain HTML and JavaScript, with no framework and no build step. The data comes from a free pu
A "99 Names of Allah" screen is one of the most common features in Muslim apps and websites. In this post we'll build one with plain HTML and JavaScript, with no framework and no build step. The data comes from a free public sample file published by SunnahSource, a set of Islamic JSON APIs (Quran, Hadith, Duas, Asma ul Husna and more).
You will end up with:
- a responsive card grid (Arabic name, transliteration, meaning)
- a language switcher driven by the JSON's translation keys
- correct right-to-left rendering for Urdu
- instant search across transliteration and meaning
Earlier posts in this series built a Flutter "Dua of the Day" widget. This one is pure web.
1. Look at the data
The sample is public and needs no key:
GET https://sunnahsource.org/data/json/asma-ul-husna.json
Shape (one item shown, translations trimmed):
{
"title": "99 Names of Allah (Asma ul Husna)",
"description": "The beautiful names of Allah with meanings in 9 languages",
"is_free": false,
"total": 99,
"items": [
{
"number": 1,
"arabic": "Ψ§ΩΨ±ΩΩΨΩΩ
ΩΩΩ",
"transliteration": "Ar-Rahman",
"translations": { "en": "The Entirely Merciful", "ur": "Ψ¨ΪΨ§ Ω
ΫΨ±Ψ¨Ψ§Ω", "fr": "Le Tout MisΓ©ricordieux" }
}
]
}
Two things matter for the UI:
-
translationsis a map keyed by language code (en,ur,fr,de,tr,ms,ru,zh-CN,ja). Build the language list from the keys instead of hard-coding it. - The public file is a sample:
totalis 99, butitemsholds only the first few names. Showitems.lengthhonestly in the UI and treattotalas what the full Asma ul Husna API returns.
2. The HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>99 Names of Allah</title>
<style>
body { font-family: system-ui, sans-serif; margin: 0; padding: 1rem; background: #f6f7f5; }
.bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.card { background: #fff; border-radius: 12px; padding: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.ar { font-size: 1.8rem; direction: rtl; text-align: right; font-family: "Amiri", "Noto Naskh Arabic", serif; }
.num { color: #0f766e; font-weight: 600; font-size: .8rem; }
.meaning[dir="rtl"] { text-align: right; }
</style>
</head>
<body>
<div class="bar">
<input id="q" type="search" placeholder="Search name or meaning" aria-label="Search">
<select id="lang" aria-label="Language"></select>
<span id="count"></span>
</div>
<div id="grid" class="grid" aria-live="polite"></div>
<script src="app.js"></script>
</body>
</html>
3. Load and cache the data
const URL_SAMPLE = "https://sunnahsource.org/data/json/asma-ul-husna.json";
const CACHE_KEY = "asma-ul-husna:v1";
const RTL = new Set(["ur", "ar", "fa"]);
async function loadNames() {
try {
const res = await fetch(URL_SAMPLE);
if (!res.ok) throw new Error("HTTP " + res.status);
const data = await res.json();
localStorage.setItem(CACHE_KEY, JSON.stringify(data));
return data;
} catch (err) {
const cached = localStorage.getItem(CACHE_KEY);
if (cached) return JSON.parse(cached); // offline fallback
throw err;
}
}
The cache means the page still works on a flaky mobile connection after the first visit.
4. Render cards safely
Never inject API text with innerHTML; build nodes and set textContent so the page is safe even if the data changes.
function card(item, lang) {
const el = document.createElement("article");
el.className = "card";
const num = document.createElement("div");
num.className = "num";
num.textContent = "#" + item.number;
const ar = document.createElement("div");
ar.className = "ar";
ar.lang = "ar";
ar.textContent = item.arabic;
const tr = document.createElement("strong");
tr.textContent = item.transliteration;
const m = document.createElement("p");
m.className = "meaning";
m.lang = lang;
m.dir = RTL.has(lang) ? "rtl" : "ltr";
m.textContent = item.translations[lang] ?? item.translations.en ?? "";
el.append(num, ar, tr, m);
return el;
}
5. Language switcher and search
const LABELS = { en: "English", ur: "Ψ§Ψ±Ψ―Ω", fr: "FranΓ§ais", de: "Deutsch", tr: "TΓΌrkΓ§e",
ms: "Bahasa Melayu", ru: "Π ΡΡΡΠΊΠΈΠΉ", "zh-CN": "δΈζ", ja: "ζ₯ζ¬θͺ" };
function normalize(s) {
return s.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").replace(/[-'\s]/g, "");
}
(async () => {
const data = await loadNames();
const items = data.items;
const langs = Object.keys(items[0]?.translations ?? { en: "" });
const select = document.getElementById("lang");
const q = document.getElementById("q");
const grid = document.getElementById("grid");
const count = document.getElementById("count");
for (const code of langs) select.add(new Option(LABELS[code] ?? code, code));
select.value = localStorage.getItem("asma-lang") ?? "en";
function render() {
const lang = select.value;
const needle = normalize(q.value);
const shown = items.filter(it =>
!needle ||
normalize(it.transliteration).includes(needle) ||
normalize(it.translations[lang] ?? "").includes(needle) ||
String(it.number) === q.value.trim()
);
grid.replaceChildren(...shown.map(it => card(it, lang)));
count.textContent = `${shown.length} of ${items.length} loaded (full list: ${data.total})`;
}
select.addEventListener("change", () => { localStorage.setItem("asma-lang", select.value); render(); });
q.addEventListener("input", render);
render();
})();
The normalize helper strips accents, hyphens and apostrophes, so "arrahman", "Ar-Rahman" and "ar rahman" all match.
6. Ideas to extend it
-
Name of the day: pick
items[dayIndex % items.length]wheredayIndexis days since epoch, the same trick used in the Flutter dua widget. - Combine with related data: the same JSON shape is used by the Azkar API, Duas API and Six Kalmas API, so the card renderer can be reused almost unchanged.
- Full data set: the sample has a handful of names; for all 99 in production, see the Asma ul Husna API page and the plans.
Links
- SunnahSource Islamic APIs: https://sunnahsource.org/
- Asma ul Husna API: https://sunnahsource.org/apis/asma-ul-husna/
- GitHub examples: https://github.com/sunnahsourceofficial-droid/sunnahsource-islamic-api
If you build something with it, I'd love to see it in the comments.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.