Sleek Dark Mode Code Block - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sleek Dark Mode Code Block</title> <style> body { margin: 0; font-family: Arial, sans-serif; background: linear-gradient(135deg, rgba(0, 0, 0, 0.5), rgba(40, 40, 40, 0.5)); display: flex; justify-content: center; align-items: center; height: 100vh; } .code-block { background: rgba(10, 10, 10, 0.7); border-radius: 10px; padding: 20px; width: 90%; max-width: 800px; color: #eaeaea; position: relative; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5); } .code-block::before { content: ''; position: absolute; top: -20px; left: -20px; right: -20px; bottom: -20px; background: linear-gradient(135deg, rgba(0, 0, 0, 0.2), rgba(40, 40, 40, 0.2)); filter: blur(20px); z-index: -1; } .code-block pre { margin: 0; padding: 0; font-size: 15px; line-height: 1.6; overflow-x: auto; background: transparent; } .code-block code { display: block; padding: 15px; border-radius: 8px; background: rgba(20, 20, 20, 0.8); border: 1px solid rgba(30, 30, 30, 0.4); color: #eaeaea; font-family: 'Courier New', Courier, monospace; } .code-block .toolbar { display: flex; justify-content: space-between; margin-bottom: 10px; } .code-block .toolbar .icon { font-size: 16px; color: #eaeaea; cursor: pointer; } .code-block .toolbar .icon:hover { color: #ff5722; } </style> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css"> </head> <body> <div class="code-block"> <div class="toolbar"> <span class="icon"><i class="fas fa-copy" title="Copy"></i></span> <span class="icon"><i class="fas fa-download" title="Download"></i></span> </div> <pre><code>const greet = () => { console.log('Hello, world!'); }; greet();</code></pre> </div> <script> document.querySelector('.fa-copy').addEventListener('click', () => { navigator.clipboard.writeText(document.querySelector('code').textContent) .then(() => alert('Code copied to clipboard!')) .catch(err => console.error('Error copying code:', err)); }); document.querySelector('.fa-download').addEventListener('click', () => { const blob = new Blob([document.querySelector('code').textContent], { type: 'text/plain' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = 'code.txt'; a.click(); URL.revokeObjectURL(url); }); </script> </body> </html>