Code Blocks

Showcase your code with syntax highlighting. Supports multiple programming languages with proper formatting and indentation.
// JavaScript example with async/await
async function fetchUserData(userId) {
try {
const response = await fetch(`/api/users/${userId}`);
const userData = await response.json();
return userData;
} catch (error) {
console.error('Failed to fetch user data:', error);
throw error;
}
}
Python example with class definition:
# Python class with type hints
from typing import List, Optional
class TaskManager:
def __init__(self) -> None:
self.tasks: List[str] = []
def add_task(self, task: str) -> None:
"""Add a new task to the list."""
self.tasks.append(task)
def get_task(self, index: int) -> Optional[str]:
"""Get a task by index, return None if not found."""
return self.tasks[index] if 0 <= index < len(self.tasks) else None
CSS styling example:
/* Modern CSS with custom properties */
:root {
--primary-color: #3b82f6;
--secondary-color: #64748b;
--border-radius: 0.5rem;
}
.card {
background: white;
border-radius: var(--border-radius);
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
padding: 1.5rem;
transition: transform 0.2s ease-in-out;
}
.card:hover {
transform: translateY(-2px);
}