Real-Time Code Editor
HTML
CSS
JavaScript
Preview
Live Preview
Ready
Share Your Code
You'll need to authorize with GitHub to create a gist.
Demo Code Examples
HTML Example
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
background-color: #f0f0f0;
}
.container {
max-width: 800px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
h1 {
color: #3498db;
}
</style>
</head>
<body>
<div class="container">
<h1>Welcome to My Page</h1>
<p>This is a sample HTML page. Try editing the code to see live changes!</p>
<button id="demo-btn">Click Me</button>
</div>
<script>
document.getElementById('demo-btn').addEventListener('click', function() {
alert('Button clicked!');
});
</script>
</body>
</html>
CSS Example
/* Basic reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Page styles */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
color: #333;
background-color: #f9f9f9;
}
/* Navigation */
nav {
background-color: #2c3e50;
padding: 1rem;
}
nav ul {
display: flex;
list-style: none;
}
nav li {
margin-right: 1rem;
}
nav a {
color: white;
text-decoration: none;
padding: 0.5rem 1rem;
border-radius: 3px;
transition: background-color 0.3s;
}
nav a:hover {
background-color: #3498db;
}
/* Card component */
.card {
background: white;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
padding: 1.5rem;
margin: 1rem 0;
}
.card h2 {
color: #3498db;
margin-bottom: 0.5rem;
}
JavaScript Example
// DOM Content Loaded event
document.addEventListener('DOMContentLoaded', function() {
// Get all buttons with class 'btn'
const buttons = document.querySelectorAll('.btn');
// Add click event to each button
buttons.forEach(button => {
button.addEventListener('click', function() {
// Toggle active class on click
this.classList.toggle('active');
// Log button text to console
console.log(`Button clicked: ${this.textContent}`);
});
});
// Form submission handler
const form = document.getElementById('contact-form');
if (form) {
form.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
const data = Object.fromEntries(formData.entries());
// Simulate form submission
console.log('Form submitted:', data);
alert('Form submitted successfully!');
this.reset();
});
}
// Fetch API example
function fetchData() {
fetch('https://jsonplaceholder.typicode.com/posts/1')
.then(response => response.json())
.then(data => {
console.log('Fetched data:', data);
document.getElementById('api-data').textContent = data.title;
})
.catch(error => console.error('Error:', error));
}
// Call fetch function
fetchData();
});