Text Voting System with Thumbs Up/Down
I'll create a clean, responsive HTML website where users can vote on text snippets with thumbs up/down buttons. The votes will be saved using JavaScript's localStorage.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Voting System</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background-color: rgba(255, 255, 255, 0.95);
border-radius: 20px;
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25);
width: 100%;
max-width: 800px;
padding: 40px;
text-align: center;
}
h1 {
color: #2c3e50;
margin-bottom: 10px;
font-size: 2.5rem;
text-shadow: 1px 1px 3px rgba(0,0,0,0.1);
}
.subtitle {
color: #7f8c8d;
margin-bottom: 30px;
font-size: 1.1rem;
}
.quote-container {
background: white;
border-radius: 15px;
padding: 30px;
margin: 30px 0;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
position: relative;
border-left: 5px solid #3498db;
}
.quote-text {
font-size: 1.5rem;
line-height: 1.6;
color: #34495e;
margin-bottom: 20px;
font-style: italic;
}
.quote-author {
text-align: right;
color: #7f8c8d;
font-size: 1.1rem;
}
.voting-buttons {
display: flex;
justify-content: center;
gap: 30px;
margin: 30px 0;
}
.vote-btn {
border: none;
background: none;
cursor: pointer;
font-size: 3.5rem;
transition: all 0.3s ease;
padding: 15px;
border-radius: 50%;
width: 100px;
height: 100px;
display: flex;
align-items: center;
justify-content: center;
}
.thumbs-up {
color: #2ecc71;
background: rgba(46, 204, 113, 0.1);
}
.thumbs-up:hover {
background: rgba(46, 204, 113, 0.2);
transform: scale(1.1) translateY(-5px);
}
.thumbs-down {
color: #e74c3c;
background: rgba(231, 76, 60, 0.1);
}
.thumbs-down:hover {
background: rgba(231, 76, 60, 0.2);
transform: scale(1.1) translateY(-5px);
}
.vote-count {
font-size: 1.8rem;
font-weight: bold;
margin-top: 10px;
display: flex;
justify-content: center;
gap: 60px;
}
.count {
min-width: 60px;
padding: 10px;
border-radius: 10px;
background: rgba(0, 0, 0, 0.03);
}
.up-count {
color: #2ecc71;
}
.down-count {
color: #e74c3c;
}
.status {
font-size: 1.2rem;
margin: 20px 0;
padding: 12px;
border-radius: 10px;
background: #f8f9fa;
display: inline-block;
}
.active {
background: rgba(52, 152, 219, 0.2);
color: #2980b9;
}
.reset-btn {
background: #3498db;
color: white;
border: none;
padding: 12px 25px;
font-size: 1rem;
border-radius: 50px;
cursor: pointer;
transition: all 0.3s;
margin-top: 20px;
box-shadow: 0 4px 10px rgba(52, 152, 219, 0.4);
}
.reset-btn:hover {
background: #2980b9;
transform: translateY(-2px);
box-shadow: 0 6px 15px rgba(52, 152, 219, 0.5);
}
.instructions {
background: #f8f9fa;
border-radius: 15px;
padding: 20px;
margin-top: 40px;
text-align: left;
}
.instructions h2 {
color: #2c3e50;
margin-bottom: 15px;
font-size: 1.4rem;
}
.instructions ul {
padding-left: 25px;
}
.instructions li {
margin-bottom: 10px;
color: #7f8c8d;
line-height: 1.5;
}
@media (max-width: 600px) {
.container {
padding: 25px 20px;
}
h1 {
font-size: 2rem;
}
.quote-text {
font-size: 1.3rem;
}
.vote-btn {
font-size: 3rem;
width: 80px;
height: 80px;
}
.voting-buttons {
gap: 15px;
}
}
</style>
</head>
<body>
<div class="container">
<h1><i class="fas fa-vote-yea"></i> Text Voting System</h1>
<p class="subtitle">Cast your vote with thumbs up or down. Your votes are saved automatically!</p>
<div class="quote-container">
<p class="quote-text">"The greatest glory in living lies not in never falling, but in rising every time we fall."</p>
<p class="quote-author">- Nelson Mandela</p>
</div>
<div class="voting-buttons">
<button id="upBtn" class="vote-btn thumbs-up">
<i class="fas fa-thumbs-up"></i>
</button>
<button id="downBtn" class="vote-btn thumbs-down">
<i class="fas fa-thumbs-down"></i>
</button>
</div>
<div class="vote-count">
<div class="count up-count">👍 <span id="upCount">0</span></div>
<div class="count down-count">👎 <span id="downCount">0</span></div>
</div>
<div id="status" class="status">Cast your vote above!</div>
<button id="resetBtn" class="reset-btn">
<i class="fas fa-sync-alt"></i> Reset Votes
</button>
<div class="instructions">
<h2><i class="fas fa-info-circle"></i> How It Works</h2>
<ul>
<li>Click the <strong>thumbs up</strong> button if you like the text</li>
<li>Click the <strong>thumbs down</strong> button if you don't like the text</li>
<li>Your vote is saved automatically using your browser's storage</li>
<li>You can change your vote at any time by clicking the other button</li>
<li>Use the reset button to clear all voting data</li>
</ul>
</div>
</div>
<script>
// DOM Elements
const upBtn = document.getElementById('upBtn');
const downBtn = document.getElementById('downBtn');
const upCount = document.getElementById('upCount');
const downCount = document.getElementById('downCount');
const status = document.getElementById('status');
const resetBtn = document.getElementById('resetBtn');
// Initialize vote counts
let votes = {
up: 0,
down: 0,
userVote: null // null, 'up', or 'down'
};
// Load saved votes from localStorage
function loadVotes() {
const savedVotes = localStorage.getItem('textVotes');
if (savedVotes) {
votes = JSON.parse(savedVotes);
}
updateUI();
}
// Save votes to localStorage
function saveVotes() {
localStorage.setItem('textVotes', JSON.stringify(votes));
}
// Update UI with current vote counts
function updateUI() {
upCount.textContent = votes.up;
downCount.textContent = votes.down;
if (votes.userVote === 'up') {
status.textContent = "You've given this a thumbs up!";
status.className = "status active";
upBtn.classList.add('active');
downBtn.classList.remove('active');
} else if (votes.userVote === 'down') {
status.textContent = "You've given this a thumbs down.";
status.className = "status active";
downBtn.classList.add('active');
upBtn.classList.remove('active');
} else {
status.textContent = "Cast your vote above!";
status.className = "status";
upBtn.classList.remove('active');
downBtn.classList.remove('active');
}
}
// Handle up vote
function handleUpVote() {
if (votes.userVote === 'up') {
// Undo the up vote
votes.up--;
votes.userVote = null;
status.textContent = "Up vote removed!";
} else {
// If switching from down vote
if (votes.userVote === 'down') {
votes.down--;
}
// Add new up vote
votes.up++;
votes.userVote = 'up';
status.textContent = "Thanks for your up vote!";
}
saveVotes();
updateUI();
}
// Handle down vote
function handleDownVote() {
if (votes.userVote === 'down') {
// Undo the down vote
votes.down--;
votes.userVote = null;
status.textContent = "Down vote removed!";
} else {
// If switching from up vote
if (votes.userVote === 'up') {
votes.up--;
}
// Add new down vote
votes.down++;
votes.userVote = 'down';
status.textContent = "Noted your down vote.";
}
saveVotes();
updateUI();
}
// Reset votes
function resetVotes() {
if (confirm("Are you sure you want to reset all votes?")) {
votes = {
up: 0,
down: 0,
userVote: null
};
saveVotes();
updateUI();
status.textContent = "All votes have been reset!";
setTimeout(() => {
status.textContent = "Cast your vote above!";
status.className = "status";
}, 3000);
}
}
// Event Listeners
upBtn.addEventListener('click', handleUpVote);
downBtn.addEventListener('click', handleDownVote);
resetBtn.addEventListener('click', resetVotes);
// Initialize
loadVotes();
</script>
</body>
</html>
Features of this Voting System:
-
Modern UI Design:
- Clean, gradient background with card-based layout
- Responsive design that works on mobile and desktop
- Smooth animations and hover effects
- Clear visual feedback for user actions
-
Voting Functionality:
- Thumbs up/down buttons with large, touch-friendly targets
- Real-time vote counters
- Status messages to confirm user actions
- Ability to change your vote
-
Data Persistence:
- Uses JavaScript localStorage to save votes between sessions
- Remembers the user's last vote
- Vote counts persist even after page refresh
-
Additional Features:
- Reset button to clear all voting data
- Instructions section explaining how to use
- Visual indicators showing which button was clicked
- Confirmation for reset action
Simply copy and paste this code into an HTML file and open it in any modern browser to start voting! The votes will be saved in your browser's localStorage.