Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


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.

+ add another resource


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.


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.


                <div class="min-h-screen p-32 bg-gray-100">

	class="relative max-w-3xl mx-auto shadow"
	<div class="flex justify-between bg-indigo-500 p-2 leading-none ">
		<div class="text-white font-extrabold">AlpineJs</div>
		<div class="divide-x-2 divide-indigo-600">
			<!-- todo: Update to use icons -->
				class="px-2 text-white hover:underline focus:outline-none"
				@click="$refs.pane.innerHTML = component.outerHTML">demo</button>
				class="px-2 text-white hover:underline focus:outline-none"
				@click="$refs.pane.innerHTML = snippet.outerHTML">source</button>
				class="px-2 text-white hover:underline focus:outline-none"
				@copy.document.prevent="copySnippet($event)">copy source</button>
	<!-- todo: prevent back button when user is scrolling inside the pane -->
	<div x-ref="pane" class="relative flex items-center justify-center" style="min-height:300px;background:#d2d8e3">
			<div x-data="{ open: false }" class="relative">
					@click="open = !open"
					@click.away="open = false"
					x-text="open ? 'close' : 'open'"
					class="rounded w-24 py-2 bg-blue-500 hover:bg-blue-400 text-white font-bold focus:outline-none">
					class="absolute mt-3 bg-white w-64 h-24 flex text-xl items-center justify-center rounded-lg shadow-lg"
					Hey there!
		class="italic text-sm absolute bottom-0 right-0 mr-2 mb-2"


                [x-cloak] { display: none; }


                // TODO: accept parameters like height, width, theme, etc
function previewHandler() {
	return {
		component: null,
		snippet: null,
		copied: false,
		setup() {
			// TODO: Doing this here is too late as Alpine already has set it up
			this.component = this.$el.querySelector('[x-data]')
			this.$refs.pane.innerHTML = this.component.outerHTML
			this.$'display', 'block')
		buildSnippet() {
			this.snippet = document.createElement('pre')
			this.snippet.classList.add('absolute', 'inset-0', 'overflow-scroll', 'bg-gray-200', 'font-mono', 'p-4', 'pt-8')
			let html = this.snippet.innerHTML
			let tokens = lolight.tok(html)

			tokens =, index) => {

				// If it's a return or new line
				if (/\r|\n/.exec(token[1])) {
					// The return should be first, ie strip leading spaces
					token[1] = token[1].replace(/\s+[\n|\r]/, '')
					// Check the length of the \r + tabs
					const length = (/\r|\n/.exec(token[1]).input.length)
					// Only set the spaces the first time
					if (typeof spacesOffset === 'undefined') {
						// The first indent should always be 1 space, 
						// so with the \r that would mean a length of 2
						spacesOffset = 2 - length
					token[1] = token[1].slice(0, (spacesOffset ? spacesOffset : length))
					// Replace tabs with 4 spaces
					token[1] = token[1].replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;')
					return token[1]
				// TODO: Might be nicer to put each directive on it's own line
				// But it will take some time to get the indentation right
				// Perhaps use the spaceOffset from above...
				// if (token[1] === '@') return '\n\t@'
				// if (token[1] === ':') return '\n\t:'
				// if (token[0] === 'key') {
				// 	if (tokens[index + 1] && tokens[index - 1][0] == 'pct') {
				// 		return token[1]
				// 	}
				// 	return '\n\t' + token[1]
				// }
				return token[1].replace(/[\u00A0-\u9999<>\&]/gim, i => '&#'+i.charCodeAt(0)+';')
			this.snippet.innerHTML = tokens
			lolight.el(this.snippet) //
		selectSnippet(event) {
			const range = document.createRange()
		copySnippet(event) {
			if (this.copied) return
			event.clipboardData.setData('text/plain', this.component.outerHTML)
			this.copied = true
			setTimeout(() => {
				this.copied = false
			}, 2000)