webdevpuneet.com

Bootstrap HTTP Status Badge — Free HTML CSS JS Snippet

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

CategoryButtons

Copy & paste

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>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

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.

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.