Code Snippet Generator

Generate sample code snippets in various languages. Great for testing and demos.Updated 2026-03-20

Frequently Asked Questions

What languages?

JavaScript, Python, HTML, CSS, SQL, and JSON.

Can I copy?

Yes, click Copy.

Free?

Yes, completely free.

\n\n
\n \n
\n \n

Welcome

\n

Hello, World!

\n \n\n',css:'/* CSS Example */\n:root {\n --primary: #6366f1;\n --bg: #0f172a;\n --text: #e2e8f0;\n}\n\n.container {\n max-width: 1200px;\n margin: 0 auto;\n padding: 0 1rem;\n}\n\n.card {\n background: var(--bg);\n border-radius: 12px;\n padding: 1.5rem;\n transition: transform 0.2s;\n}\n\n.card:hover {\n transform: translateY(-4px);\n}',sql:'-- SQL Example\nSELECT \n u.id,\n u.name,\n u.email,\n COUNT(o.id) AS order_count,\n SUM(o.total) AS total_spent\nFROM users u\nLEFT JOIN orders o ON u.id = o.user_id\nWHERE u.created_at >= \'2024-01-01\'\n AND u.active = true\nGROUP BY u.id, u.name, u.email\nHAVING COUNT(o.id) > 0\nORDER BY total_spent DESC\nLIMIT 20;',json:'{\n "name": "my-project",\n "version": "1.0.0",\n "description": "A sample project",\n "main": "index.js",\n "scripts": {\n "start": "node index.js",\n "dev": "nodemon index.js",\n "test": "jest",\n "build": "webpack --mode production"\n },\n "dependencies": {\n "express": "^4.18.0",\n "cors": "^2.8.5"\n }\n}'};function gen(lang){document.querySelectorAll('.lang-btn').forEach(function(b){b.className='btn btn-secondary lang-btn'});event.target.className='btn btn-primary lang-btn';document.getElementById('code').textContent=snippets[lang]}function copyCode(){navigator.clipboard.writeText(document.getElementById('code').textContent).then(function(){alert('Copied!')})}gen('js');