Error

Error

Contributed by Heran Wang

Learn how to create an error page.

View in New Tab

Code Usage

How to Create an Error Page

An error page, like a 404 Not Found page, informs users that the page they're trying to reach is unavailable. It's an essential part of web design, ensuring that users have a path forward when they encounter a dead end. This guide will help you create a simple and effective error page using the provided CSS.

Setup Your HTML File

Create a new HTML file and include the basic HTML structure:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Error Page</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <!-- Error page content goes here -->
</body>
</html>

Add CSS for Error Page

The following CSS to set global defaults for padding, margin, and list styles, and define default link behavior:

* {
  padding: 0;
  margin: 0;
  list-style: none;
}
 
a {
  color: #141414;
  text-decoration: none;
}
 
a:hover {
  color: #000;
}

Define the Main Container

Style the .main class to centralize the main content area of the error page:

.main {
  width: 100%;
  max-width: 1168px;
  margin: 0 auto;
}

Style the Error Message

Inside the .main container, add your error message and stylize it using the .titleColumn and .bcom classes:

.titleColumn h1 {
  color: #141414;
  margin-bottom: 35px;
  font-size: 45px;
  font-weight: normal;
}
 
.bcom p {
  color: #141414;
  margin-bottom: 35px;
  font-size: 15px;
  font-weight: normal;
}

Creating a Responsive Layout

Use media queries to make your error page responsive. Adjust the layout for different device sizes:

@media screen and (max-width:998px) and (min-width:768px) {
  .container {
    width: 100%;
  }
}
 
@media screen and (max-width:768px) and (min-width:320px) {
  .container {
    width: 100%;
  }
  .right, .middle {
    width: 100%;
    float: none;
  }
}

Footer Style

Customize the footer to provide a consistent look across all pages:

.footer {
  line-height: 450px;
  background-color: #c63a1e;
  color: #fff;
  text-align: center;
  font-size: 30px;
}

Conclusion

This tutorial covers how to create a simple yet effective error page using HTML and CSS. Remember to test the page to ensure it displays correctly across different devices and browsers. Additionally, consider adding navigation links or a search bar to help lost users find their way.

Version

VersionEditorAuthorDateDescription
v1.0Heran WangHeran Wang20/OCT/2023Initial version
v2.0Heran WangHeran Wang01/NOV/2023Full version
v3.0Heran WangHeran Wang04/NOV/2023Verify updates