Creating a simplified version of the ChatGPT website in a single HTML file is a fun exercise, but keep in mind that the actual ChatGPT website is a complex, dynamic application with JavaScript, APIs, and backend services. For this example, I'll create a static HTML page that mimics the look and feel of a chatbot interface, including a header, chat area, and input field. I'll also add some basic CSS for styling and a little JavaScript for interactivity (e.g., displaying user messages). However, this won't include actual AI functionality—just a static mockup.
Here’s the complete code for a single HTML file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ChatGPT Mockup</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
background-color: #f4f4f4;
}
/* Header */
header {
background-color: #202123;
color: white;
padding: 15px 20px;
display: flex;
justify-content: space-between;
align-items: center;
}
header h1 {
font-size: 24px;
}
header nav a {
color: white;
text-decoration: none;
margin-left: 20px;
font-size: 16px;
}
/* Main Chat Area */
main {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
background-color: #ececec;
}
.chat-container {
width: 100%;
max-width: 800px;
height: 80vh;
background-color: white;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
}
.chat-box {
flex: 1;
padding: 20px;
overflow-y: auto;
border-bottom: 1px solid #ddd;
}
.message {
margin-bottom: 20px;
padding: 10px;
border-radius: 5px;
max-width: 80%;
}
.user-message {
background-color: #d1e7dd;
margin-left: auto;
text-align: right;
}
.bot-message {
background-color: #f8d7da;
}
/* Input Area */
.input-area {
display: flex;
padding: 20px;
border-top: 1px solid #ddd;
background-color: #f9f9f9;
}
.input-area input {
flex: 1;
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 5px;
outline: none;
}
.input-area button {
padding: 10px 20px;
margin-left: 10px;
background-color: #10a37f;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
.input-area button:hover {
background-color: #0d8c6e;
}
/* Footer */
footer {
background-color: #202123;
color: white;
text-align: center;
padding: 10px;
font-size: 14px;
}
</style>
</head>
<body>
<!-- Header -->
<header>
<h1>ChatGPT Mockup</h1>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Login</a>
</nav>
</header>
<!-- Main Chat Area -->
<main>
<div class="chat-container">
<div class="chat-box" id="chatBox">
<div class="message bot-message">
Hello! I'm a mockup of ChatGPT. Type a message below to see it appear here.
</div>
</div>
<div class="input-area">
<input type="text" id="userInput" placeholder="Type your message...">
<button onclick="sendMessage()">Send</button>
</div>
</div>
</main>
<!-- Footer -->
<footer>
© 2023 ChatGPT Mockup. All rights reserved.
</footer>
<!-- JavaScript for Interactivity -->
<script>
function sendMessage() {
const userInput = document.getElementById('userInput');
const chatBox = document.getElementById('chatBox');
const messageText = userInput.value.trim();
if (messageText === '') return;
// Create user message
const userMessage = document.createElement('div');
userMessage.classList.add('message', 'user-message');
userMessage.textContent = messageText;
chatBox.appendChild(userMessage);
// Clear input
userInput.value = '';
// Auto-scroll to the bottom
chatBox.scrollTop = chatBox.scrollHeight;
// Simulate bot response (static for this mockup)
setTimeout(() => {
const botMessage = document.createElement('div');
botMessage.classList.add('message', 'bot-message');
botMessage.textContent = "This is a static mockup. I can't respond like the real ChatGPT, but I can display your messages!";
chatBox.appendChild(botMessage);
chatBox.scrollTop = chatBox.scrollHeight;
}, 500);
}
// Allow pressing Enter to send message
document.getElementById('userInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
sendMessage();
}
});
</script>
</body>
</html>
Explanation of the Code:
-
HTML Structure:
- The page is divided into three main sections:
header, main, and footer.
- The
header contains a title and navigation links.
- The
main section contains a chat container with a chat box (for messages) and an input area (for typing messages).
- The
footer contains a simple copyright notice.
-
CSS Styling:
- The styling is designed to resemble a modern chat interface, with a clean layout, rounded corners, and a color scheme inspired by the ChatGPT website.
- Flexbox is used to center and align elements.
- Messages are styled differently for user and bot responses (green for user, red for bot in this mockup).
- The chat box has a scrollbar for overflow content.
-
JavaScript Interactivity:
- The
sendMessage function captures the user's input, displays it as a user message, and simulates a bot response (static text in this case).
- The chat box auto-scrolls to the bottom when new messages are added.
- The Enter key is supported for sending messages.
-
Limitations:
- This is a static mockup, not a functional AI chatbot. It doesn't connect to any backend or API (like the real ChatGPT does).
- The bot response is hardcoded and doesn't use AI to generate replies.
- For a fully functional chatbot, you would need to integrate a backend service (e.g., using OpenAI's API) and handle more complex JavaScript logic.
How to Use:
- Copy the entire code into a file named
index.html.
- Open the file in a web browser.
- Type a message in the input field and click "Send" (or press Enter) to see it appear in the chat box, followed by a static bot response.
This mockup provides a starting point for building a more complex chatbot interface if you decide to add backend functionality or integrate with an AI API.