Source Code

<div class="container py-5 d-flex justify-content-center">
  <div class="card bshttp-card">
    <div class="card-body p-4">
      <label class="form-label small fw-semibold">Enter a status code</label>
      <input type="text" class="form-control mb-3" id="bshttpInput" placeholder="e.g. 404" maxlength="3">

      <div class="d-flex align-items-center gap-2 mb-4" id="bshttpResult">
        <span class="text-muted small">Type a 3-digit code above.</span>
      </div>

      <p class="small fw-semibold text-muted mb-2">Common codes</p>
      <div class="d-flex flex-wrap gap-2" id="bshttpCommon"></div>
    </div>
  </div>
</div>

Bootstrap HTTP Status Badge — Free HTML CSS JS Snippet

Bootstrap HTTP Status Badge · Misc · Plain HTML, CSS & JS · Live preview

What's included

Features

Status families are derived from numeric range tests, not a hardcoded table of every possible code
Correctly classifies any valid 3-digit code, including ones outside the common-codes reference list
Non-digit input is stripped live, so the field can never hold an invalid character
An explicit neutral state for empty or out-of-range input instead of a misleading guessed badge
Clicking a reference chip and typing a code by hand both drive the exact same render function

About this UI Snippet

Bootstrap HTTP Status Badge — HTML, CSS & JavaScript

Screenshot of the Bootstrap HTTP Status Badge snippet rendered live

Every status code's color and label are derived from one small FAMILIES array of range tests, not a giant lookup table mapping each of the hundreds of possible 3-digit codes individually — familyFor(code) just finds the first family whose test(code) returns true, which is what correctly colors a code like 418 (a real, if joking, HTTP status) as a client error even though it never appears in the COMMON list at all.

The input itself is scrubbed on every keystroke with input.value.replace(/[^0-9]/g, ''), so pasting or typing a non-digit character never produces a broken or misleading badge — the field can only ever contain digits, and render() explicitly handles the "nothing typed yet" and "out of the valid 100-599 range" cases with a neutral placeholder rather than guessing at a family for invalid input.

Clicking a common-code chip and typing the same number by hand both funnel through the exact same render() function, so the live badge above always reflects one consistent piece of state regardless of which interaction produced it.

Build with AI

Build, Understand, Optimize, and Extend It With AI

Hand this snippet to an AI coding assistant like Claude and ask it to add the official reason phrase for every common code (not just the family label), or to add a short one-line explanation of what each family generally means (e.g. "4xx: the request was likely wrong") shown beneath the live badge.

Prompt to recreate it

Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:

text
Build an interactive Bootstrap 5.3 HTTP status code badge reference, using the real Bootstrap CDN framework (bootstrap.min.css and bootstrap.bundle.min.js), not custom CSS made to resemble it.

Requirements:
- A text input restricted to digits only (strip any non-digit character as the user types) that accepts a 3-digit HTTP status code.
- Classify any entered code into one of four families using numeric range checks (not a hardcoded per-code table): 2xx success, 3xx redirect, 4xx client error, 5xx server error, each with a distinct Bootstrap badge color.
- Live-render a colored badge and family label above the input as the user types, with an explicit neutral placeholder state when the input is empty or outside the valid 100-599 range.
- Below the input, show a row of at least 10 clickable chips for common real-world status codes (200, 404, 500, etc.), each pre-colored by its own family. Clicking a chip fills the input with that code and updates the live badge through the same rendering logic used for manual typing.

Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.

Step by step

How to Use

  1. 1
    Load the snippetThe input is empty and a neutral placeholder message shows above the common-codes list.
  2. 2
    Type "404"A yellow "404" badge appears immediately labeled "Client Error".
  3. 3
    Change it to "500"The badge turns red and relabels itself "Server Error" live as you finish typing.
  4. 4
    Try typing a letterIt's silently stripped out — the field only ever accepts digits.
  5. 5
    Click any common-code chip below, like "429"The input updates to match and the badge reflects that code, exactly as if you'd typed it.

Real-world uses

Common Use Cases

DEV
API documentation and internal developer references
Pairs with bootstrap-api-response-viewer for a fuller request/response inspection panel.
Admin dashboards showing request or webhook logs
Reuse the same familyFor() mapping to color-code a live table of recent API call outcomes.
Learning and teaching HTTP status code families
A hands-on reference for anyone still building the instinct for which status range means what.

Got questions?

Frequently Asked Questions

Yes — familyFor() tests the numeric value against a range, not a name lookup, so any valid code from 100-599 gets classified correctly by family even if it never appears among the labeled reference chips.

render() explicitly checks for a missing value or one outside 100-599 and shows a neutral "type a code" placeholder rather than forcing an incorrect family guess onto invalid input.

Yes. Keep FAMILIES and COMMON as plain data, track the current code in component state, and derive the badge's color/label with the same familyFor() logic inside the render function.

Add a small lookup object mapping specific codes to their official reason phrases, and fall back to just the family label (as this snippet does) for any code not explicitly listed.