Docs / Pages and packages
Web pages
A Web Snippet is a real web page that runs beside the editor, with its console under it.
On this page
Start one from the Web Page Starter, or from React, Vue, Svelte and the other browser Starters (Starters). The page runs in a real browser, in a process of its own, with a web page’s access and no more.
Edit the page in Parts
A Web Snippet is one HTML document. The strip above the editor shows it in three Parts, one at a time:
- HTML: the markup inside
<body>. - CSS: the styles inside
<style>. - JS (or TS in TypeScript): the code inside the last
<script>. It is the only Part that is checked and run.
Markup, style and script
Click a tab to edit that Part. Each Part has its own undo, so undoing in the CSS never takes back what you typed in the JS. A line number in an error is a line of the script Part. Click it in the console, and JSpark opens that Part and goes to the line.
A React, Preact or Solid Snippet shows JSX and CSS only: its markup is the element the library renders into. A Vue or Svelte Snippet has no strip. It is one component file, edited whole, as in a Vue or Svelte project.
Run the page
Press ⌘↵ or Ctrl+Enter to run the page. It appears beside the code, and what it prints appears in its console. Before the first Run, the pane says Run it to see the page.
Components and hooks
0
−+- With Run as you type on, the page is built again as you type. When the build changes, the page reloads and starts over; a CSS change counts. An edit that changes nothing, such as a comment, leaves the page as it is.
- The page keeps running, and keeps its state, while another tab is on screen.
- A page that never finishes can’t hang JSpark: it runs in its own process.
- The page can call APIs with
fetch, as any web page can. - The Timeline replays Node Snippets only. A page has no Timeline.
Style the page
The CSS Part is the page’s stylesheet, in its <head>. JSpark adds only a margin reset and a default font before it, so your rules win. A <style> you write inside the HTML Part stays part of the markup.
With @import "tailwindcss"; in the CSS Part, JSpark builds the stylesheet with Tailwind before the page loads. Every Starter with a CSS Part begins with that line. See Tailwind CSS.
Load code from the web
A page may load code from the web, as any page can. Each of these works:
- An import from a URL in the script, such as
import { format } from "https://esm.sh/date-fns". - A
<script src="https://…">, a stylesheet or a font from anhttps:address, in the HTML Part. - An import map in the HTML Part, so the script can import by name.
- Inline handlers you wrote in the HTML, such as
onclick="hello()", andeval.
Code from the web needs a connection. A package imported by name, such as react in the React Starter, comes from the Packages window instead. When your page’s import map names a package, your mapping wins.
One thing is refused: a script added after the page started, for example through innerHTML. The console says when something was refused.
Give the console more or less room
Beside a page, the console’s heading has two buttons. They are the two arrangements you are not in:
- Hide console: the console shrinks to its heading. Click the heading to bring it back.
- Show both: the page and the console share the side, the page above or beside the console.
- Hide page: the console takes the whole side. The page keeps running, out of sight.
Markup, style and script
JSpark keeps your choice for every page, and starts with both shown.
When a page freezes
When a page stops answering for more than a second, JSpark lays The page froze over it. Only the page is stuck. The editor and the rest of JSpark keep working.
Markup, style and script
The page froze
Only the page is stuck. Hiding won’t stop it.
Stop page- Press Stop page. The page ends, and the footer says Stopped.
- Fix the code that keeps the page busy, such as a loop that never ends.
- Press ⌘↵ or Ctrl+Enter to run it again.
If the page starts answering again by itself, the message goes away.
JSpark also stops a page by itself when it is still loading after the time limit, or when it uses more memory than the memory limit. A page that has loaded and waits for a click is never stopped for time. See Time and memory limits.
The pictures show JSpark on a Mac. On Windows, the window looks a little different and uses Ctrl for ⌘, but everything works the same way.