JavaScript
About JavaScript Preprocessors
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Learn more · Versions
Babel includes JSX processing.
Add External Scripts/Pens
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
Powered by
About External Resources
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Learn more
? When linking another Pen as a resource, make sure you use a URL Extension of the type of code you want to link to. Either URL Extension Required
.css
, .js
, or the extension of a matching code processor.
Add Packages
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Powered by
About Packages
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
Behavior
Auto Save
If active, Pens will autosave every 30 seconds after being saved once.
Auto-Updating Preview
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
Format on Save
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Editor Settings
Code Indentation
Want to change your Syntax Highlighting theme, Fonts and more?
Visit your global Editor Settings.
Editor Commands
Ctrl Ctrl Space Autocomplete
F Find
G Find Next
⇧ G Find Previous
⇧ Opt F Find & Replace
⇧ F Format Code
[ Indent Code Right
] Indent Code Left
⇧ Tab Auto Indent Code
/ Line Comment
⇧ Opt / Block Comment
Also see: Tab Triggers
Editor Focus
Alt Opt 1 HTML Editor
Alt Opt 2 CSS Editor
Alt Opt 3 JS Editor
Alt Opt 4 Toggle Console
Alt Opt 0 Preview
Esc Exit currently focused editor
Misc
⇧ 7 Re-run Preview
⇧ 8 Clear All Analyze Errors
⇧ 9 Open This Dialog
⇧ 0 Open Debug View
HTML Specific
⇧ A Wrap With...
Pen Actions
P Create New Pen
S Save
⇧ S Save As Private PRO
I Info Panel (if owned)