Creating a dark-themed 404 error page involves HTML for the structure, CSS for styling, and JavaScript for any interactive or dynamic elements. Below is an example of each component working together to create a simple dark-themed 404 error page.
The HTML defines the content structure, the CSS applies the dark theme and layout, and the JavaScript can be used for adding functionality like a button to go back to the homepage.
- HTML (save as
404.html):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 Not Found</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="main-container">
<h1>404</h1>
<p>The darkness you see is the void where the page used to be.</p>
<button id="go-back">Go Back</button>
</div>
<script src="script.js"></script>
</body>
</html>
- CSS (save as
styles.css):
body, html {
height: 100%;
margin: 0;
font-family: 'Arial', sans-serif;
background-color: #121212;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
text-align: center;
}
#main-container {
max-width: 600px;
}
h1 {
font-size: 5em;
margin: 0;
color: #bb86fc;
}
p {
font-size: 1.5em;
}
#go-back {
margin-top: 20px;
padding: 10px 20px;
font-size: 1em;
background-color: #bb86fc;
color: #121212;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
#go-back:hover {
background-color: #9a67ea;
}
- JavaScript (save as
script.js):
document.getElementById('go-back').addEventListener('click', function() {
history.back();
});
To see this in action, you would simply need to create three files (404.html, styles.css, and script.js) with the content provided above, and then open the 404.html file in a web browser.
The HTML structure includes a main container with a large 404 message, a paragraph explaining the error, and a button to go back to the previous page. The CSS applies a dark theme with a purple accent color for the 404 message and the button. The JavaScript adds functionality to the "Go Back" button, allowing users to return to the previous page when clicked.