A professional, full-featured web-based code editor for HTML, CSS, and JavaScript with live preview functionality. Built with vanilla JavaScript, this editor provides a complete development environment in your browser.
- Three Separate Editors: Dedicated panels for HTML, CSS, and JavaScript
- Line Numbers: Auto-updating line numbers for all editors
- Character Count: Real-time character count for each editor
- Tab Support: Proper tab handling (2 spaces) in all editors
- Syntax Validation: Real-time validation with error reporting
- Code Formatting: Auto-format your HTML, CSS, and JS code
- Copy to Clipboard: Quick copy buttons for each editor
- Instant Preview: See your changes in real-time
- Sandboxed iframe: Safe execution environment
- Fullscreen Mode: Expand preview to fullscreen
- Refresh Control: Manual refresh option
- Responsive: Preview adjusts to different screen sizes
- Console Capture: Captures console.log, console.error, console.warn, console.info
- Error Handling: Displays runtime JavaScript errors
- Collapsible Panel: Toggle console visibility
- Clear Console: Easy console clearing
- Syntax Highlighting: Different colors for log types
- Auto-Save: Automatic saving to localStorage
- Save Projects: Save multiple named projects
- Load Projects: Quick access to saved projects
- Delete Projects: Manage your saved projects
- Export HTML: Download complete HTML file
- Dark/Light Theme: Toggle between themes with persistent preference
- Layout Toggle: Switch between vertical and horizontal layouts
- Responsive Design: Works on desktop, tablet, and mobile
- Smooth Animations: Professional transitions and effects
- Notifications: Toast notifications for all actions
- Keyboard Shortcuts: Productivity-enhancing shortcuts
- Modal Dialogs: Clean save/load interfaces
Ctrl+Enter/Cmd+Enter- Run codeCtrl+S/Cmd+S- Save projectCtrl+Shift+F/Cmd+Shift+F- Format current editorTab- Insert 2 spaces in editorsEsc- Close modals (when focused)
- Clone or Download this repository
- Open
index.htmlin your web browser - Start coding! No build process or dependencies required
web-code-editor/
β
βββ index.html # Main HTML file
βββ styles.css # Complete styling
βββ script.js # All functionality
βββ README.md # Documentation
-
Write Code
- Enter HTML in the HTML editor
- Add CSS in the CSS editor
- Write JavaScript in the JS editor
-
Run Preview
- Click the "Run" button or press
Ctrl+Enter - Your code will execute in the preview panel
- Click the "Run" button or press
-
Save Your Work
- Click "Save" button
- Enter a project name
- Project is saved to browser localStorage
-
Load Projects
- Click "Load" button
- Select from your saved projects
- Code is loaded into editors
Click the magic wand icon (β¨) on any editor to auto-format your code.
Click the moon/sun icon to toggle between dark and light themes.
Click the columns icon to switch between vertical and horizontal layouts.
Click "Export" to download a complete, standalone HTML file with all your code.
- Console automatically captures output from your JavaScript
- View logs, errors, and warnings
- Toggle visibility with the console button
HTML Validation
- Checks for basic tag structure
- Validates opening and closing tags
- Identifies self-closing tags
CSS Validation
- Validates balanced braces
- Checks for basic syntax errors
JavaScript Validation
- Uses Function constructor for syntax checking
- Displays line-specific errors
- Runtime error catching
All data is stored in browser's localStorage:
autoSave_html- Auto-saved HTML codeautoSave_css- Auto-saved CSS codeautoSave_js- Auto-saved JavaScript codesavedProjects- Array of saved projectseditorTheme- Theme preference (dark/light)editorLayout- Layout preference (vertical/horizontal)
- β Chrome/Edge (Recommended)
- β Firefox
- β Safari
- β Opera
β οΈ Internet Explorer (Not supported)
- Uses sandboxed iframe for preview
- Prevents malicious code from affecting parent page
- Safe execution environment with
allow-scripts,allow-same-origin, etc.
Edit the CSS variables in styles.css:
:root {
--primary-color: #4a90e2; /* Main accent color */
--secondary-color: #7b68ee; /* Secondary accent */
--success-color: #2ecc71; /* Success messages */
--warning-color: #f39c12; /* Warnings */
--danger-color: #e74c3c; /* Errors */
}Light theme variables can be adjusted:
body.light-theme {
--bg-primary: #f5f5f5;
--bg-secondary: #ffffff;
/* Customize other colors */
}- Code formatting is basic (not a full parser)
- Validation is simplified (not as comprehensive as IDE)
- localStorage has size limits (~5-10MB)
- Some advanced JavaScript features may not work in iframe
- No real-time collaboration features
Potential features for future versions:
- Syntax highlighting with CodeMirror or Monaco Editor
- Auto-complete suggestions
- Multiple file support
- Git integration
- Export to CodePen/JSFiddle
- Custom color schemes
- Plugin system
- Collaborative editing
- Cloud storage integration
- Use keyboard shortcuts for faster workflow
- Format code regularly for better readability
- Save frequently with descriptive project names
- Check console for JavaScript errors and logs
- Use fullscreen preview for better visualization
- Try both layouts to find what works best for you
Feel free to:
- Report bugs
- Suggest features
- Submit pull requests
- Share your improvements
This project is open source and available under the MIT License.
- State Management: Global state object tracks all editor states
- Event-Driven: Uses event listeners for all interactions
- Modular Functions: Each feature is isolated in its own function
- No Dependencies: Pure vanilla JavaScript (except Font Awesome for icons)
- Debouncing not implemented (consider for large codebases)
- Auto-save triggers on every input (could be optimized)
- Line numbers recalculate on every keystroke (acceptable for small files)
If you encounter any issues or have questions:
- Check this README
- Review the console for errors
- Clear localStorage if experiencing issues
- Refresh the page
- Font Awesome for icons
- Inspired by CodePen, JSFiddle, and other online code editors
- Built with β€οΈ for developers
Happy Coding! π
Made with passion for web development