Elegant Neon 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>Elegant Neon Code Block</title> <style> body { margin: 0; font-family: Arial, sans-serif; background: linear-gradient(135deg, rgba(255, 0, 0, 0.6), rgba(0, 255, 255, 0.6)); display: flex; justify-content: center; align-items: center; height: 100vh; } .code-block { background: rgba(0, 0, 0, 0.6); border-radius: 15px; padding: 20px; width: 80%; max-width: 800px; color: #e0e0e0; position: relative; box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3); overflow: hidden; } .code-block::before { content: ''; position: absolute; top: -20px; left: -20px; right: -20px; bottom: -20px; background: linear-gradient(135deg, rgba(255, 0, 0, 0.2), rgba(0, 255, 255, 0.2)); filter: blur(25px); z-index: -1; } .code-block pre { margin: 0; padding: 0; font-size: 16px; line-height: 1.6; overflow-x: auto; background: transparent; } .code-block code { display: block; padding: 15px; border-radius: 10px; background: rgba(0, 0, 0, 0.8); border: 1px solid rgba(255, 255, 255, 0.4); color: #e0e0e0; font-family: 'Courier New', Courier, monospace; } .code-block .toolbar { display: flex; justify-content: space-between; margin-bottom: 10px; } .code-block .toolbar .icon { font-size: 18px; color: #e0e0e0; cursor: pointer; transition: color 0.3s; } .code-block .toolbar .icon:hover { color: #ff00ff; } </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>