HTML Status Codes

Beginner
10 min read
Updated: Nov 2026
3 examples
1xx–5xx

Definition and Usage

When a browser loads your HTML page, an image, a stylesheet, or a script, the server answers with an HTTP status code—a three-digit number that says whether the request worked, redirected, or failed.

Status codes are not HTML tags. They sit in the HTTP layer around your document. As an HTML author you meet them most often as broken <a> links (404), missing <img> files, permanent URL moves (301), and custom error pages.

First digit = class.

2xx success, 3xx redirect, 4xx client/URL problem, 5xx server problem. Memorize those four for day-to-day HTML work.

Beginner tip.

In DevTools → Network, every HTML, CSS, JS, and image request shows a Status. In JavaScript, fetch() exposes response.status and response.ok (true for 200–299).

Soft 404 trap.

Do not return 200 OK with an empty “page not found” HTML body. Use a real 404 (or 410 if the page is gone forever) so browsers and search engines understand.

How a Response Looks

response.txt
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8

<!DOCTYPE html>
<html lang="en">
  <!-- your HTML document -->
</html>

Pattern: browser requests a URL → server sends a status line (200 OK, 404 Not Found, …) → headers → optional body (often your HTML).

Five Status Classes

RFC 9110 groups responses by the first digit:

ClassRangeMeaning for HTML authors
1xx100–199Informational — rare in everyday page loads
2xx200–299Success — HTML / assets delivered
3xx300–399Redirection — browser follows a new URL
4xx400–499Client error — bad link, auth, or request
5xx500–599Server error — hosting or app failure

Codes You See With HTML Pages

Focus on these while building and debugging sites:

CodeNameHTML author note
200OKPage or file loaded successfully
301Moved PermanentlyOld URL renamed forever — update <a href> and sitemaps
302FoundTemporary redirect
304Not ModifiedBrowser reused a cached CSS/JS/image
403ForbiddenServer refuses access (permissions)
404Not FoundBroken link or missing image/file
500Internal Server ErrorServer-side failure — check host logs
503Service UnavailableMaintenance or overload — try again later

2xx — Success

CodeNameShort meaning
200OKRequest succeeded (typical HTML GET)
201CreatedNew resource created (often after POST)
204No ContentSuccess with an empty body
206Partial ContentRange request (media / downloads)

3xx — Redirection

CodeNameShort meaning
301Moved PermanentlyNew permanent URL
302FoundTemporary new URL
304Not ModifiedUse the cached copy
307Temporary RedirectTemporary; keep the same HTTP method
308Permanent RedirectPermanent; keep the same HTTP method

4xx — Client Error

CodeNameShort meaning
400Bad RequestMalformed request
401UnauthorizedAuthentication required
403ForbiddenKnown client, access denied
404Not FoundURL has no resource
405Method Not AllowedWrong HTTP method for that URL
410GoneResource deleted permanently
429Too Many RequestsRate limited

5xx — Server Error

CodeNameShort meaning
500Internal Server ErrorUnexpected server failure
502Bad GatewayInvalid response from upstream
503Service UnavailableOverloaded or down for maintenance
504Gateway TimeoutUpstream timed out

HTML Examples

Read real status codes with fetch(). Use Try It Yourself for a live editor.

Example 1 — Read 200 OK for an HTML Page

Fetch a real tutorial page and print its status.

JS
fetch('/html/status-code')
  .then(function (response) {
    console.log(response.status);      // 200
    console.log(response.statusText);  // OK
    console.log(response.ok);          // true
  });
Try It Yourself

How It Works

  1. Browser requests the HTML URL.
  2. Server returns 200 OK with the document.
  3. response.ok is true for any 2xx.
  4. Same idea for CSS, JS, and image URLs.

Example 2 — Trigger 404 Not Found

A missing path mimics a broken href or src.

JS
fetch('/html/this-page-does-not-exist')
  .then(function (response) {
    console.log(response.status);  // 404
    console.log(response.ok);      // false
  });
Try It Yourself

How It Works

  1. fetch does not throw on 404.
  2. Check response.status yourself.
  3. In HTML, fix typos in <a href> and <img src>.
  4. Or add a 301 to the correct URL.

Example 3 — Status Code Lookup

Type a code and see its class plus a short meaning.

HTML
<input type="number" id="code" value="404">
<button type="button" id="btn">Look up</button>
<pre id="out"></pre>
Try It Yourself

How It Works

  1. Divide by 100 for the class (404 → 4xx).
  2. Map common codes to short HTML-friendly meanings.
  3. Open Try It for a live interactive lookup.
  4. Use tables above for less common codes.

Edge Cases & Pitfalls

Most HTML-related status bugs are wrong codes for missing pages or silent broken assets.

404

Broken links and images

Check Network for red 404 rows after you change href / src. Fix paths or redirect.

200

Do not fake 404 with 200

A friendly error page still needs a 404/410 status so SEO and tools stay honest.

301

Permanent moves need 301/308

Renaming a page? Redirect the old URL and update internal links.

fetch

fetch does not throw on 404

Only network failures reject the promise. Always read response.status.

Browser Support

All modern browsers understand standard HTTP status codes when loading HTML and assets.

FeatureSupport
HTTP status line (1xx–5xx)All modern browsers
DevTools Network Status columnChrome, Firefox, Edge, Safari
fetch() response.status / okAll modern browsers
Following 3xx redirectsAutomatic in browsers (APIs can customize)

Key Takeaways

  • Not HTML markup—status codes wrap how your pages are delivered.
  • 2xx / 3xx / 4xx / 5xx cover almost every HTML debugging case.
  • 404 usually means fix a link or file path.
  • Use DevTools Network to see status for every HTML asset.

One line: learn the five classes, then treat daily HTML work as a loop of 200, 301, 404, and 500.

Frequently Asked Questions

A three-digit number the server sends with every response (for example 200 OK or 404 Not Found). It tells the browser whether the HTML page, image, or other resource loaded, redirected, or failed.
No. They belong to HTTP. Your HTML file is the body of a successful response. You see codes in DevTools Network, not inside the <html> source.
The server found the resource and returned it. For a normal page visit, that usually means the HTML document (and later its CSS, JS, and images) loaded successfully.
The URL does not match a resource. Common HTML causes: typo in an a href or img src, a deleted page, or a missing file. Fix the link or add a redirect.
301 Moved Permanently means the URL changed forever (search engines should update). 302 Found is temporary — the original URL may still be the main one.
Open DevTools → Network, reload, and check the Status column. In JavaScript, fetch() exposes response.status and response.ok after each request.

Next: HTML Drag and Drop

Make elements movable with the draggable attribute and drop targets.

Drag and drop →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful