ButtonsThe welcome document the htmlcssjs.net playground opens with: a card, a button and an output box wired with JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>My Playground</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="container">
<h1>Welcome to htmlcssjs.net</h1>
<p>Edit this code to see live changes!</p>
<button id="demoButton" class="btn">Click Me</button>
<div id="output" class="output"></div>
</div>
</body>
</html>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
color: #333;
line-height: 1.6;
}
.container {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #4f46e5;
border-bottom: 2px solid #4f46e5;
padding-bottom: 10px;
margin-top: 0;
}
.btn {
background-color: #4f46e5;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
.btn:hover {
background-color: #4338ca;
}
.output {
margin-top: 20px;
padding: 15px;
background-color: #f8fafc;
border-radius: 6px;
border-left: 4px solid #4f46e5;
}
document.getElementById('demoButton').addEventListener('click', function() {
const output = document.getElementById('output');
output.innerHTML = '<h3>Button Clicked!</h3><p>You successfully executed JavaScript code.</p>';
// Create a dynamic element
const newElement = document.createElement('div');
newElement.innerHTML = '<p>This element was created dynamically with JavaScript.</p>';
newElement.style.backgroundColor = '#e0f2fe';
newElement.style.padding = '10px';
newElement.style.borderRadius = '5px';
newElement.style.marginTop = '10px';
output.appendChild(newElement);
// Log to console
console.log('Button clicked at: ' + new Date().toLocaleTimeString());
});
// Additional demo function
function showMessage() {
alert('Hello from the playground!');
}
Buttons
Cards
NavigationA responsive navigation bar with a logo, menu links and a mobile toggle.