Free Code Compiler

Online Code CompilerRun and preview HTML, CSS, and JavaScript instantly in one place. Write, edit, and test your web code with real-time live preview. A fast, free, and user-friendly coding playground for beginners and developers.

Code Compiler- Fixed Code Editor
HTML
CSS
JavaScript
Preview
Ln 1, Col 1
Dark
Toggle Theme
Change Layout
Import Project
Export Project
Clear All
`; }if (!this.editors.css.value.trim()) { this.editors.css.value = `/* Add your CSS styles here */ .container { text-align: center; }button { background-color: #9D00FF; color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 16px; margin-top: 20px; }button:hover { background-color: #7a00cc; }`; }if (!this.editors.js.value.trim()) { this.editors.js.value = `// Add your JavaScript here console.log('Hello from NeonCode!');// Example function function showMessage() { const message = "This is a message from your JavaScript code!"; console.log(message); return message; }// You can also use modern JS features const add = (a, b) => a + b; console.log(\`5 + 3 = \${add(5, 3)}\`);`; }// Initialize cursor position this.updateCursorPosition(this.editors.html); },setupSplitPanes() { // Only initialize Split.js on desktop if (window.innerWidth > 768) { const editorPanes = [ document.querySelector('[data-pane="html"]'), document.querySelector('[data-pane="css"]'), document.querySelector('[data-pane="js"]'), document.querySelector('[data-pane="preview"]') ];Split(editorPanes, { sizes: [25, 25, 25, 25], minSize: 100, gutterSize: 8, snapOffset: 0, direction: 'horizontal' }); } },updatePreview() { const html = this.editors.html.value; const css = this.editors.css.value; const js = this.editors.js.value;const previewDoc = this.previewFrame.contentDocument || this.previewFrame.contentWindow.document; // Clear console when updating preview this.clearConsole(); previewDoc.open(); previewDoc.write(` ${html}
`); previewDoc.close(); // Listen for console messages from the iframe window.addEventListener('message', (e) => { if (e.data && e.data.type === 'console') { this.logToConsole(e.data.level, e.data.message); } }); },logToConsole(level, message) { const entry = document.createElement('div'); entry.className = `console-entry console-${level}`; entry.textContent = `[${new Date().toLocaleTimeString()}] ${message}`; this.consolePanel.appendChild(entry); this.consolePanel.scrollTop = this.consolePanel.scrollHeight; },clearConsole() { this.consolePanel.innerHTML = '
Console cleared
'; },toggleConsole() { this.isConsoleVisible = !this.isConsoleVisible; if (this.isConsoleVisible) { this.consolePanel.classList.remove('hidden'); } else { this.consolePanel.classList.add('hidden'); } },toggleFullscreenPreview() { if (document.fullscreenElement) { document.exitFullscreen(); } else { this.previewFrame.requestFullscreen(); } },activateMobilePane(pane) { // Update mobile nav buttons this.mobileNavButtons.forEach(btn => { if (btn.getAttribute('data-pane') === pane) { btn.classList.add('active'); } else { btn.classList.remove('active'); } }); // Show the selected pane document.querySelectorAll('.pane-container').forEach(container => { if (container.getAttribute('data-pane') === pane) { container.classList.add('active-pane'); } else { container.classList.remove('active-pane'); } }); },toggleSettingsMenu() { this.settingsMenu.classList.toggle('open'); },handleSettingsAction(action) { switch(action) { case 'theme': this.toggleTheme(); break; case 'layout': this.toggleLayout(); break; case 'import': this.importProject(); break; case 'export': this.exportProject(); break; case 'clear': this.clearAll(); break; } },toggleTheme() { this.currentTheme = this.currentTheme === 'dark' ? 'light' : 'dark'; document.documentElement.classList.toggle('light-theme'); this.editorTheme.textContent = this.currentTheme === 'dark' ? 'Dark' : 'Light'; this.showStatus(`Theme changed to ${this.currentTheme}`); },toggleLayout() { this.layout = this.layout === 'horizontal' ? 'vertical' : 'horizontal'; // This would require reinitializing Split.js with different options this.showStatus(`Layout changed to ${this.layout}`); },formatCode(type) { try { let formatted; if (type === 'html') { formatted = html_beautify(this.editors.html.value, { indent_size: 2, indent_char: ' ', max_preserve_newlines: 1, preserve_newlines: true, wrap_line_length: 80 }); this.editors.html.value = formatted; } else if (type === 'css') { formatted = css_beautify(this.editors.css.value, { indent_size: 2, indent_char: ' ', selector_separator_newline: true }); this.editors.css.value = formatted; } else if (type === 'js') { formatted = js_beautify(this.editors.js.value, { indent_size: 2, indent_char: ' ', preserve_newlines: true }); this.editors.js.value = formatted; } this.showStatus(`${type.toUpperCase()} formatted successfully`); this.updatePreview(); } catch (error) { this.showStatus(`Error formatting ${type.toUpperCase()}: ${error.message}`, 5000); } },clearEditor(type) { if (confirm(`Are you sure you want to clear the ${type.toUpperCase()} editor?`)) { this.editors[type].value = ''; this.showStatus(`${type.toUpperCase()} editor cleared`); this.updatePreview(); } },saveToLocalStorage() { const project = { html: this.editors.html.value, css: this.editors.css.value, js: this.editors.js.value, timestamp: new Date().getTime() }; localStorage.setItem('neoncode-project', JSON.stringify(project)); this.lastSave = project.timestamp; },loadFromLocalStorage() { const saved = localStorage.getItem('neoncode-project'); if (saved) { try { const project = JSON.parse(saved); this.editors.html.value = project.html || ''; this.editors.css.value = project.css || ''; this.editors.js.value = project.js || ''; this.lastSave = project.timestamp; this.showStatus('Project loaded from local storage'); } catch (e) { console.error('Error loading from local storage:', e); } } },setupAutosave() { // Autosave every 30 seconds this.autosaveInterval = setInterval(() => { if (this.isAutosaveEnabled) { this.saveToLocalStorage(); } }, 30000); },exportProject() { const zip = new JSZip(); // Add files to zip zip.file("index.html", this.editors.html.value); zip.file("styles.css", this.editors.css.value); zip.file("script.js", this.editors.js.value); // Generate zip file zip.generateAsync({type:"blob"}) .then(function(content) { saveAs(content, "neoncode-project.zip"); }); this.showStatus('Project exported as ZIP'); },importProject() { // Create file input element const fileInput = document.createElement('input'); fileInput.type = 'file'; fileInput.accept = '.zip,.html,.css,.js'; fileInput.onchange = (e) => { const file = e.target.files[0]; if (!file) return; const reader = new FileReader(); reader.onload = (e) => { const content = e.target.result; if (file.name.endsWith('.zip')) { // Handle ZIP import JSZip.loadAsync(content).then(zip => { const promises = []; if (zip.file('index.html')) { promises.push(zip.file('index.html').async('string').then(html => { this.editors.html.value = html; })); } if (zip.file('styles.css')) { promises.push(zip.file('styles.css').async('string').then(css => { this.editors.css.value = css; })); } if (zip.file('script.js')) { promises.push(zip.file('script.js').async('string').then(js => { this.editors.js.value = js; })); } Promise.all(promises).then(() => { this.updatePreview(); this.showStatus('Project imported from ZIP'); }); }); } else if (file.name.endsWith('.html')) { this.editors.html.value = content; this.showStatus('HTML file imported'); } else if (file.name.endsWith('.css')) { this.editors.css.value = content; this.showStatus('CSS file imported'); } else if (file.name.endsWith('.js')) { this.editors.js.value = content; this.showStatus('JS file imported'); } this.updatePreview(); }; reader.readAsText(file); }; fileInput.click(); },clearAll() { if (confirm('Are you sure you want to clear all editors?')) { this.editors.html.value = ''; this.editors.css.value = ''; this.editors.js.value = ''; this.updatePreview(); this.showStatus('All editors cleared'); } },updateCursorPosition(editor) { const cursorPos = this.getCursorPosition(editor); this.cursorPosition.textContent = `Ln ${cursorPos.line}, Col ${cursorPos.column}`; },getCursorPosition(editor) { // For textarea, we can calculate line and column from selection const cursorPosition = editor.selectionStart; const text = editor.value.substring(0, cursorPosition); const lines = text.split('\n'); return { line: lines.length, column: lines[lines.length - 1].length + 1 }; },showStatus(message, duration = 3000) { // Create status message element if it doesn't exist let statusEl = document.getElementById('status-message'); if (!statusEl) { statusEl = document.createElement('div'); statusEl.id = 'status-message'; statusEl.style.position = 'fixed'; statusEl.style.bottom = '70px'; statusEl.style.left = '50%'; statusEl.style.transform = 'translateX(-50%)'; statusEl.style.backgroundColor = 'var(--accent-primary)'; statusEl.style.color = 'white'; statusEl.style.padding = '8px 16px'; statusEl.style.borderRadius = 'var(--border-radius)'; statusEl.style.zIndex = '10000'; statusEl.style.boxShadow = 'var(--shadow-accent)'; statusEl.style.fontSize = '0.875rem'; document.body.appendChild(statusEl); } statusEl.textContent = message; statusEl.style.display = 'block'; // Hide after duration setTimeout(() => { statusEl.style.display = 'none'; }, duration); },debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } };// Initialize the app app.init();// Make app available globally for debugging window.neonCode = app; });
Explore More Tools

Color Picker

JSON Formatter

Regex Tester

CSS Code Generator

HTML Code Generator

Explore More Tools

Scroll to Top