Basic Structure
- HTML: Create the structure of the dashboard.
- CSS: Style the dashboard to make it visually appealing.
- JavaScript: Add interactivity and dynamic data (simulated in this case).
Step 1: HTML
Create an index.html
file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Social Media Dashboard</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<header>
<h1>Social Media Dashboard</h1>
</header>
<div class="stats">
<div class="stat-card">
<h2>Followers</h2>
<p id="followersCount">0</p>
</div>
<div class="stat-card">
<h2>Likes</h2>
<p id="likesCount">0</p>
</div>
<div class="stat-card">
<h2>Posts</h2>
<p id="postsCount">0</p>
</div>
</div>
<button id="updateButton">Update Stats</button>
</div>
<script src="script.js"></script>
</body>
</html>
Step 2: CSS
Create a styles.css
file:
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
header {
text-align: center;
margin-bottom: 20px;
}
.stats {
display: flex;
justify-content: space-between;
}
.stat-card {
background: #e7e7e7;
padding: 20px;
border-radius: 8px;
text-align: center;
flex: 1;
margin: 0 10px;
}
button {
display: block;
width: 100%;
padding: 10px;
background-color: #007bff;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 20px;
}
button:hover {
background-color: #0056b3;
}
Step 3: JavaScript
Create a script.js
file:
document.getElementById('updateButton').addEventListener('click', updateStats);
function updateStats() {
const followersCount = Math.floor(Math.random() * 1000);
const likesCount = Math.floor(Math.random() * 5000);
const postsCount = Math.floor(Math.random() * 100);
document.getElementById('followersCount').textContent = followersCount;
document.getElementById('likesCount').textContent = likesCount;
document.getElementById('postsCount').textContent = postsCount;
}
Running the Dashboard
- Save the files in the same directory.
- Open
index.html
in a web browser. - Click the “Update Stats” button to see random statistics.
Extending the Dashboard
You can expand this basic dashboard by:
- Integrating real APIs (like the Twitter API, Instagram Graph API, etc.) to fetch live data.
- Adding charts using libraries like Chart.js for better visualization.
- Implementing user authentication to personalize the dashboard for different users.
Leave a Reply