A counter such as “124 / 500” can sit next to your server address on any page that allows JavaScript. The example below calls MCAPI and reads players.online from the Minecraft status response. It renders ordinary text that you can style alongside the rest of your site.
Add the HTML example
Paste this into your page body and replace mc.hypixel.net with the address players enter in Minecraft. Uncomment the marked line for Bedrock. If players enter a custom port, use address:port.
<p id="mc-players" role="status">Loading player count…</p>
<script>
async function showPlayerCount() {
const label = document.getElementById('mc-players');
const address = 'mc.hypixel.net';
const url = new URL('https://mcapi.tr/api/v1/status/' + encodeURIComponent(address));
// url.searchParams.set('bedrock', 'true');
try {
const response = await fetch(url, { signal: AbortSignal.timeout(12000) });
if (!response.ok) throw new Error('HTTP ' + response.status);
const data = await response.json();
if (!data.online || !Number.isInteger(data.players?.online)) {
throw new Error('No player count');
}
const format = new Intl.NumberFormat('en');
const count = format.format(data.players.online);
const capacity = Number.isInteger(data.players.max) && data.players.max > 0
? ' / ' + format.format(data.players.max)
: '';
label.textContent = count + capacity + (data.stale ? ' (last known count)' : '');
} catch {
label.textContent = "Server status unavailable";
}
}
showPlayerCount();
</script>
Handle zero, stale data and failed checks
- A successful response with
players.online: 0displays 0. stale: truemeans the count came from a previous successful check. The example labels it as the last known count.- A DNS error, timeout or rate limit leaves the count unknown. The example displays a separate message for that case.
One request per page load is enough for a basic counter. If you add automatic updates, wait at least 60 seconds after each completed request and slow down when you receive 429. With a Content Security Policy, allow https://mcapi.tr in connect-src. If your site editor strips scripts, use the iframe widget linked below.