Modern Glassmorphism Code Block - VexaX
Run Code
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>Modern Glassmorphism Code Block</title> <style> body { margin: 0; font-family: Arial, sans-serif; background: linear-gradient(135deg, rgba(0, 204, 255, 0.5), rgba(255, 0, 150, 0.5)); display: flex; justify-content: center; align-items: center; height: 100vh; } .code-block { background: rgba(255, 255, 255, 0.2); border-radius: 12px; padding: 20px; width: 90%; max-width: 800px; color: #f5f5f5; position: relative; overflow: hidden; box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2); } .code-block::before { content: ''; position: absolute; top: -20px; left: -20px; right: -20px; bottom: -20px; background: linear-gradient(135deg, rgba(0, 204, 255, 0.1), rgba(255, 0, 150, 0.1)); filter: blur(30px); z-index: -1; } .code-block pre { margin: 0; padding: 0; font-size: 14px; line-height: 1.6; overflow-x: auto; background: transparent; } .code-block code { display: block; padding: 15px; border-radius: 10px; background: rgba(255, 255, 255, 0.15); border: 1px solid rgba(255, 255, 255, 0.3); color: #202020; 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: #e0e0e0; cursor: pointer; } .code-block .toolbar .icon:hover { color: #00ccff; } </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>