
When a browser requests a webpage (HTML or other resources), the server responds with an HTTP status code to tell the browser whether the request was successful, redirected, or failed.
1. What Are HTTP Status Codes?
- Definition: 3-digit numbers sent by the server in the status line of an HTTP response.
- Purpose: Indicate the result of the request (success, error, redirect, etc.).
- Structure:
HTTP/1.1 200 OK Content-Type: text/html
2. Categories of HTTP Status Codes
HTTP status codes are divided into 5 classes based on the first digit:
Category | Range | Meaning |
---|---|---|
1xx | 100–199 | Informational – request received, processing continues |
2xx | 200–299 | Success – request successfully received and processed |
3xx | 300–399 | Redirection – further action needed (e.g., new URL) |
4xx | 400–499 | Client errors – problem with the request |
5xx | 500–599 | Server errors – problem with the server |
3. Common HTTP Status Codes Table
Status Code | Name | Meaning | HTML Example Scenario |
---|---|---|---|
100 | Continue | Initial part of request OK; continue sending | Large form upload |
200 | OK | Request successful; HTML content in body | Page loaded normally |
201 | Created | New resource created | HTML form creates an account |
204 | No Content | Request OK, no body returned | AJAX form submission with no data back |
301 | Moved Permanently | Resource moved; browser should use new URL | Redirect from http:// to https:// |
302 | Found (Redirect) | Temporarily moved to another URL | Temporary redirect after login |
304 | Not Modified | Resource not changed; use cached version | Browser caching HTML/CSS |
307 | Temporary Redirect | Same method used; new URL given | Temporary maintenance page |
400 | Bad Request | Invalid request syntax | Wrong HTML form data format |
401 | Unauthorized | Authentication required | Login page without credentials |
403 | Forbidden | Access denied | Trying to open admin page without rights |
404 | Not Found | Resource not found | HTML page doesn’t exist |
405 | Method Not Allowed | HTTP method not supported | Using POST instead of GET in HTML form |
408 | Request Timeout | Server timed out waiting for request | Slow HTML form submission |
409 | Conflict | Request conflicts with server state | Duplicate registration in form |
410 | Gone | Resource removed permanently | Old HTML page deleted |
429 | Too Many Requests | User sent too many requests | Refreshing HTML form too fast |
500 | Internal Server Error | Server crashed or misconfigured | HTML page fails to load due to PHP error |
502 | Bad Gateway | Invalid response from upstream server | Proxy fetching HTML from backend fails |
503 | Service Unavailable | Server overloaded or down | Maintenance mode page |
504 | Gateway Timeout | Upstream server didn’t respond | Slow backend service for HTML content |
4. How They Appear in HTML
Example of a 200 OK response:
HTTP/1.1 200 OK
Content-Type: text/html
<!DOCTYPE html>
<html>
<head><title>Home</title></head>
<body>
<h1>Welcome!</h1>
</body>
</html>
Example of a 404 Not Found response:
HTTP/1.1 404 Not Found
Content-Type: text/html
<!DOCTYPE html>
<html>
<head><title>Not Found</title></head>
<body>
<h1>Page Not Found</h1>
</body>
</html>