HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
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.
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.
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.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id='app'>
<div v-html='header'></div>
<div class='flex justify-around items-start'>
<div class='text-center p-4 rounded bg-white text-center shadow-lg'>
<strong>Target (Click To Edit)</strong>
<hr><br>
<textarea class='editable' v-model='data.trim()'>
{{ data.trim() }}
</textarea>
</div>
<div class='text-center mt-20 p-4 rounded bg-white text-center shadow-lg'>
<strong class='editable'><-</strong>
<strong>Target</strong>
</div>
<div class='text-center shadow-lg mt-4 p-4 rounded bg-white' style='border:1px solid #d5d5d5;'>
<span id='try-it'></span>
<div class='mt-10 text-center'>
<input
id='data_get_path'
class='text-center'
type='text'
v-model='path'
ref='in'
placeholder="Ex: meta.location"
/><hr>
</div>
<br><br>
<code style='color:red'>data_get(target, {{ path.trim() !== '' ? `"${path}"` : "path" }}, fallback)</code>
<br>
</div>
<div class='text-center mt-20 p-4 rounded bg-white text-center shadow-lg'>
<strong>Output</strong>
<strong class='output'>-></strong>
</div>
<div class='text-center p-4 rounded bg-white text-center shadow-lg'>
<strong>Output (Click Try It Now To Update)</strong>
<br><hr><br>
<pre class='output'><code>{{ dataGet }}</code></pre>
</div>
</div>
</div>
</div>
</div>
</div>
body, html, #app {
background-color: #f5f5f5 !important;
}
.editable {
text-align: left;
font-size: 12px;
border-radius: 3px;
background-color: #dddd;
border: 1px dashed purple;
padding: 6px;
color: indigo;
width: 400px;
}
textarea.editable {
min-height: 1050px !important;
}
.output {
text-align: left;
color: orange;
width: 400px;
padding: 6px;
font-size: 12px;
border: 2.5px solid orange;
border-radius: 6px;
background-color: #333;
}
// body {
// background-color: #f5f5f5;
// }
// .data_get {
// position: fixed;
// bottom: 0;
// left: 0;
// border: 1px solid orange;
// min-width: 50vw;
// }
// .data_get > div {
// background-color:#d3d3d3;
// font-size:14px;
// color: #333;
// font-weight: bolder;
// div {
// font-size: 12px;
// font-weight: lighter;
// width: 100%;
// background-color: #333;
// color: orange;
// }
// }
// input, button {
// border: 1px solid #d5d5d5;
// border-radius: 3px;
// height: 3px;
// width:100%;
// padding: 5px;
// }
// .messages-container {
// padding: 10px;
// position:relative;
// bottom: 110px;
// left: 4.45%;
// width: 50vw;
// }
// button:disabled {
// opacity: 0.5 !important;
// }
// h1, h2 {
// color: #333333b3;
// font-weight: heavy;
// }
// #app {
// div.danger {
// border: 1px solid #de3618;
// background-color: #de3618;
// }
// padding-bottom: 15px;
// }
// .form {
// box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
// }
// pre {
// position: fixed;
// top: 0;
// right: 0;
// margin-top:67px;
// margin-right: 0vw;
// width:25vw;
// code: {
// padding: 10px;
// }
// padding: 10px;
// border-radius: 6px;
// background-color:#333;
// color:orange;
// padding:3px;
// font-size:10px;
// width:25vw;
// }
// textarea {
// position:fixed;
// top:0;
// right:100;
// margin-right:25vw;
// margin-top: 67px;
// min-height:100%;
// background-color:#333;
// color:#fff;
// font-size:10px;
// width:25vw;
// }
const user = 'zhorton34';
const repo = 'laravel-js-helpers';
const title = 'Laravel JS Helpers';
const subtitle = 'Nested Object Accessors';
const { data_get, data_set, data_fill } = laravelJsHelpers;
let data = JSON.stringify({meta: { location: { address_1: '5555', address_2: 'suite #2', zip_code: '55343', city: 'New York', state: 'NY' }, phone_number: '555 5555 5555', email: 'user@example.com', id: 1 },
actions: {
likes: [
{ time: '3 hrs ago', type_id: 12342, type: 'Actionable/Post', resource_name: 'post', path: '/posts/12342' },
{ time: '4.5 hrs ago', type_id: 21132, type: 'Actionable/Post', resource_name: 'post', path: '/posts/12342' },
{ time: '2d 6 hrs ago', type_id: 124522, type: 'Actionable/Post', resource_name: 'post', path: '/posts/124522' },
{ time: '2w 4d 3.5 hrs ago', type_id: 5342, type: 'Actionable/Comment', resource_name: 'post.comment', path: '/posts/12342/comments/5342' }
],
posts: [
{ id: 1, title: 'Hello world', description: 'universal worlds say hello' },
{ id: 2, title: 'Goodbye world',description: 'multi verse stuff' }
]
}
},
undefined, 4);
new Vue({
el: '#app',
data: () => ({ data, path: '' }),
mounted() {
this.$refs.in.focus();
const afterStep = async (step, instance) => {
this.path = instance.getElement().value;
};
const simple = new TypeIt('#data_get_path', {
afterStep,
cursorChar: '|', cursor: true, lifeLike: true, html: false
})
.pause(1000)
.type('m')
.pause(200)
.type('e')
.pause(200)
.type('t')
.type('a')
.pause(300)
.type('.location')
.pause(2000)
.type('.city')
.pause(2500)
.delete(5)
.pause(2500)
.delete(9)
.pause(2000)
.delete(4)
.type('actions').pause(2000).type('.likes').pause(2500).type('.*.type')
new TypeIt('#try-it', {
cursorChar: '|',
cursor: true,
lifeLike: true,
loop: false,
html: true,
afterComplete: async (step, instance) => { simple.go(); },
})
.type('Check', { delay: 300 })
.delete(1)
.type('it out')
.pause(300)
.delete(6)
.type('k it out for')
.pause(100)
.break()
.type('your', { delay: 300 } )
.type('self!')
.go();
},
/** Helpers stored in computed to clean up purpose of pen **/
computed: {
user,
repo,
dataGet: $this => data_get(JSON.parse($this.data), $this.path, data),
header: $this => `
<div class="w-full flex">
${$this.npm} ${$this.github}
</div>
`,
title: $this =>`
<h1 class='${$this.classes.h1}'>${title}</h1>
<h2 class='${$this.classes.h2}'>(${subtitle})</h2>
`,
links: $this => $this.errors().any() ? ``: `<div class="${$this.classes.banner}"> ${$this.github + $this.html}</div>`,
classes: $this => ({
h1: 'text-4xl mt-8',
h2: 'text-2sm',
header: 'text-center mb-8 text-2xl',
banner: 'flex w-full justiy-center mb-8',
container: 'flex justify-around align-items-stretch',
form: 'w-100%',
errors: 'border border-gray-400 bg-white rounded messages-container w-100%',
danger: 'mb-3 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded',
btn: 'bg-blue-500 text-white font-bold py-2 px-4 rounded-full w-1/2 mt-4',
}),
npm: () => `
<div class="bg-red-700 text-center py-4 lg:px-4 w-1/2">
<div class="p-2 bg-white items-center text-grey-100 leading-none lg:rounded-full flex lg:inline-flex" role="alert">
<a href='https://www.npmjs.com/package/${repo}'>
<span class="flex rounded-full b-white-500 px-2 py-1 text-xs font-bold ml-2">Npm Package</span>
</a>
<svg class="fill-current opacity-75 h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M12.95 10.707l.707-.707L8 4.343 6.586 5.757 10.828 10l-4.242 4.243L8 15.657l4.95-4.95z"/>
</svg>
</div>
</div>
`,
github: () => `
<div style='background-color: #24292e;' class="w-1/2 text-center py-4 lg:px-4">
<div class="p-2 bg-white items-center text-grey-100 leading-none lg:rounded-full flex lg:inline-flex" role="alert">
<a href='https://github.com/${user}/${repo}'>
<span class="flex rounded-full b-white-500 px-2 py-1 text-xs font-bold ml-2">Github Repository</span>
</a>
<svg class="fill-current opacity-75 h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
<path d="M12.95 10.707l.707-.707L8 4.343 6.586 5.757 10.828 10l-4.242 4.243L8 15.657l4.95-4.95z"/>
</svg>
</div>
</div>
`,
}
});
Also see: Tab Triggers