Skip to content

Repository files navigation

RunCode.js – embed a code editor directly into any webpage.

VersionLicensejsDelivrjsDelivr

Features

  • Lightweight (19 kB only) and zero-dependency
  • Live preview that updates as you type
  • Separate editors for HTML, CSS, and JavaScript
  • Supports Browser CDN, ES Modules, and CommonJS environments
  • Customizable themes
  • Secure sandboxed iframe preview

Getting Started

Choose the installation method that fits your project setup.

Browser (CDN)

The simplest way to use RunCode. Drop the script tag into any HTML page - no build step needed. The library is loaded directly from a CDN and attaches to any element matching the selector you provide.

<divclass="editor"></div><scriptsrc="https://unpkg.com/runcodejs"></script><script>consteditor=newRunCode({element: '.editor',code: {html: '<h1>Hello World</h1>',css: 'h1 { color: #38bdf8; }',js: 'console.log("ready");'}});</script>

ES Modules

For modern JavaScript projects using native ES module syntax. Install via npm, then import RunCode directly into your module. Works out of the box with bundlers like Vite, Rollup, and webpack.

npm install runcodejs
<divclass="editor"></div><scripttype="module">importRunCodefrom'runcodejs';newRunCode({element: '.editor',code: {html: '<h1>Hello World</h1>',css: 'h1 { color: #38bdf8; }',js: 'console.log("ready");'}});</script>

CommonJS

For Node.js-based environments or older bundler setups that rely on require(). Fully compatible with tools like Browserify or older webpack configurations.

constRunCode=require('runcodejs');newRunCode({element: '.editor',code: {html: '<h1>Hello World</h1>',css: 'h1 { color: #38bdf8; }',js: 'console.log("ready");'}});

Configuration

The RunCode constructor accepts a configuration object. At minimum, you need an element selector and a code object with at least one of html, css, or js.

newRunCode({element: '.editor',// CSS selector or DOM element to mount intocode: {html: '...',// Initial HTML contentcss: '...',// Initial CSS contentjs: '...'// Initial JavaScript content}});

All three code fields are optional - you can provide just html, just js, or any combination depending on your use case.

Documentation

Detailed documentation is split into focused reference pages.

  • API Reference - complete list of constructor options, instance methods, and TypeScript types
  • Extract - how to pull initial code content from existing DOM elements instead of passing it inline
  • Security - details on the sandboxed iframe, network access controls, and dialog restrictions
  • Themes - applying built-in themes and creating your own custom editor theme
  • Examples - runnable code samples covering common use cases
  • Changelog - version history and release notes

License

RunCode is licensed under MIT. Copyright © Hemanta Gayen.

About

A lightweight HTML, CSS and JavaScript playground with live preview.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages