Here's a simplified Twitter-like website in a single HTML file with embedded CSS and JavaScript:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Twitter Clone</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
display: flex;
background-color: #ffffff;
}
.sidebar {
width: 250px;
height: 100vh;
padding: 20px;
position: fixed;
border-right: 1px solid #e6ecf0;
}
.logo {
color: #1da1f2;
font-size: 30px;
margin-bottom: 20px;
}
.sidebar-menu {
list-style: none;
}
.sidebar-menu li {
padding: 15px 0;
font-size: 20px;
cursor: pointer;
}
.sidebar-menu li:hover {
color: #1da1f2;
}
.main-content {
margin-left: 250px;
width: 600px;
border-right: 1px solid #e6ecf0;
}
.tweet-box {
padding: 20px;
border-bottom: 1px solid #e6ecf0;
}
.tweet-input {
width: 100%;
height: 100px;
border: none;
resize: none;
font-size: 18px;
margin-bottom: 10px;
padding: 10px;
}
.tweet-button {
background-color: #1da1f2;
color: white;
border: none;
padding: 10px 20px;
border-radius: 20px;
cursor: pointer;
float: right;
}
.feed {
padding: 20px;
}
.tweet {
padding: 15px;
border-bottom: 1px solid #e6ecf0;
}
.tweet-header {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.profile-pic {
width: 40px;
height: 40px;
border-radius: 50%;
margin-right: 10px;
background-color: #1da1f2;
}
.tweet-actions {
display: flex;
justify-content: space-between;
max-width: 300px;
margin-top: 10px;
color: #657786;
}
.tweet-action {
cursor: pointer;
}
.tweet-action:hover {
color: #1da1f2;
}
.trending {
position: fixed;
margin-left: 850px;
width: 300px;
padding: 20px;
background-color: #f5f8fa;
border-radius: 15px;
margin-top: 20px;
}
.trending h2 {
margin-bottom: 20px;
}
.trending-item {
margin-bottom: 15px;
cursor: pointer;
}
.trending-item:hover {
background-color: #eaf5fd;
}
</style>
</head>
<body>
<div class="sidebar">
<div class="logo">
<i class="fab fa-twitter"></i>
</div>
<ul class="sidebar-menu">
<li><i class="fas fa-home"></i> Home</li>
<li><i class="fas fa-hashtag"></i> Explore</li>
<li><i class="far fa-bell"></i> Notifications</li>
<li><i class="far fa-envelope"></i> Messages</li>
<li><i class="far fa-bookmark"></i> Bookmarks</li>
<li><i class="far fa-user"></i> Profile</li>
</ul>
</div>
<div class="main-content">
<div class="tweet-box">
<textarea class="tweet-input" placeholder="What's happening?"></textarea>
<button class="tweet-button" onclick="postTweet()">Tweet</button>
</div>
<div class="feed" id="tweet-feed">
<!-- Tweets will be added here -->
</div>
</div>
<div class="trending">
<h2>What's happening</h2>
<div class="trending-item">
<small>Trending in Technology</small>
<p>#JavaScript</p>
<small>50.4K Tweets</small>
</div>
<div class="trending-item">
<small>Trending in Sports</small>
<p>#Football</p>
<small>32.1K Tweets</small>
</div>
<div class="trending-item">
<small>Trending in Music</small>
<p>#NewAlbum</p>
<small>28.7K Tweets</small>
</div>
</div>
<script>
function postTweet() {
const tweetInput = document.querySelector('.tweet-input');
const tweetText = tweetInput.value.trim();
if (tweetText) {
const feed = document.getElementById('tweet-feed');
const tweet = document.createElement('div');
tweet.className = 'tweet';
tweet.innerHTML = `
<div class="tweet-header">
<div class="profile-pic"></div>
<div>
<strong>User Name</strong>
<span style="color: #657786;"> @username · Just now</span>
</div>
</div>
<div class="tweet-content">
${tweetText}
</div>
<div class="tweet-actions">
<div class="tweet-action"><i class="far fa-comment"></i> 0</div>
<div class="tweet-action"><i class="fas fa-retweet"></i> 0</div>
<div class="tweet-action"><i class="far fa-heart"></i> 0</div>
<div class="tweet-action"><i class="far fa-share-square"></i></div>
</div>
`;
feed.insertBefore(tweet, feed.firstChild);
tweetInput.value = '';
}
}
// Add some sample tweets
const sampleTweets = [
"Just learned about async/await in JavaScript! 🚀 #coding #webdev",
"Beautiful day for a walk in the park! 🌳 #nature",
"Working on a new project. Can't wait to share it with everyone! 💻"
];
window.onload = function() {
sampleTweets.forEach(tweetText => {
const feed = document.getElementById('tweet-feed');
const tweet = document.createElement('div');
tweet.className = 'tweet';
tweet.innerHTML = `
<div class="tweet-header">
<div class="profile-pic"></div>
<div>
<strong>Sample User</strong>
<span style="color: #657786;"> @sampleuser · 2h</span>
</div>
</div>
<div class="tweet-content">
${tweetText}
</div>
<div class="tweet-actions">
<div class="tweet-action"><i class="far fa-comment"></i> 5</div>
<div class="tweet-action"><i class="fas fa-retweet"></i> 3</div>
<div class="tweet-action"><i class="far fa-heart"></i> 10</div>
<div class="tweet-action"><i class="far fa-share-square"></i></div>
</div>
`;
feed.appendChild(tweet);
});
}
</script>
</body>
</html>
This code creates a simplified Twitter-like interface with the following features:
- Left sidebar with navigation menu
- Main content area with tweet composition box
- Tweet feed with sample tweets
- Trending section on the right
- Ability to post new tweets
- Like, retweet, comment, and share buttons (non-functional)
- Responsive design elements
- Twitter-like color scheme and styling
Key features:
- Uses Font Awesome icons for the Twitter logo and action buttons
- Implements a simple tweet posting functionality
- Includes sample tweets that load on page start
- Maintains Twitter's three-column layout
- Uses similar colors and styling to Twitter
To use this, simply save it as an HTML file and open it in a web browser. Note that you'll need an internet connection for the Font Awesome icons to load.
The website isn't fully functional (no authentication, no real backend, no real-time updates, etc.), but it demonstrates the core visual components and basic interactivity of Twitter's interface.