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.
-
const COLUMNS = [
{
title: "To Do",
tasks: [
"Uses contenteditable",
"Click to Edit!"
]
},
{
title: "Click to Edit!",
tasks: [
"Creating Demo",
"Practice DOM manipulation"
]
},
{
title: "CSS",
tasks: [
"Learn flexbox"
]
}
]
.board
for column in COLUMNS
.board__column.column
.column__content
.column__title(contenteditable='true')= column.title
.column__tasks(ondrop="ON_DROP(event)" ondragover="ALLOW_DROP(event)")
if column.tasks
for task in column.tasks
.task(draggable="true" ondragstart="ON_DRAG_START(event)")
button.task__remove(title="Remove task" onclick="REMOVE_TASK(event)") Remove task
svg(viewBox="0 0 352 512" width="24" title="times")
path(d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z")
.task__content(contenteditable="true")= task
button.column__add(title="Add task" onclick="ADD_TASK(event)") Add task
svg(viewBox="0 0 512 512" width="24" title="plus-circle")
path(d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z")
@import url('https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap');
*
box-sizing border-box
body
min-height 100vh
display flex
align-items center
justify-content center
font-family 'Patrick Hand', cursive
font-size 2rem
background hsl(180, 25%, 25%)
.board
display flex
width 80%
height calc(100vh - 2rem)
border 1rem solid hsl(35, 40%, 40%)
overflow-y hidden
&__column
flex 1 1 100%
.column
background hsl(0, 0%, 98%)
display flex
flex-direction column
flex 1 0 300px
overflow auto
&__content
flex 1
overflow auto
display flex
flex-direction column
&__tasks
flex 1 1 auto
overflow-y auto
&__add
position relative
height 44px
background transparent
color transparent
border 0
opacity 0.25
cursor pointer
flex 0 0 44px
&:hover
opacity 1
transition opacity .2s
svg
position absolute
top 50%
left 50%
transform translate(-50%, -50%)
&__title
text-align center
padding 1rem
flex 0 0 auto
font-weight bold
text-decoration underline
.task
width 90%
min-height 100px
background hsl(50, 90%, 70%)
margin 0.5rem auto
position relative
-webkit-clip-path polygon(0 0, 100% 0, 100% calc(100% - 30px), calc(100% - 30px) 100%, 0 100%)
clip-path polygon(0 0, 100% 0, 100% calc(100% - 30px), calc(100% - 30px) 100%, 0 100%)
&__content
padding 2rem
&:after
content ''
height 30px
width 30px
background linear-gradient(135deg, hsl(50, 90%, 30%) 49%, hsl(0, 0%, 98%) 50%)
position absolute
right 0
bottom 0
&__remove
cursor pointer
background transparent
border 0
opacity 0.25
height 44px
width 44px
position absolute
top 0
right 0
color transparent
overflow hidden
&:hover
opacity 1
transition opacity 0.2s
svg
position absolute
top 50%
left 50%
transform translate(-50%, -50%)
let destination
const TASK_TEMPLATE = (_, ...keys) => {
return `
<div class="task" draggable="true" ondragstart="ON_DRAG_START(event)">
<button class="task__remove" title="Remove task" onclick="REMOVE_TASK(event)">Remove task
<svg viewBox="0 0 352 512" width="24" title="times">
<path d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path>
</svg>
</button>
<div class="task__content" contenteditable >${keys[0]}</div>
</div>
`
}
window.ALLOW_DROP = e => {
e.preventDefault()
if (e.target.className === 'column__tasks') destination = e.target
}
window.ON_DROP = e => {
e.preventDefault()
const TASK_ID = e.dataTransfer.getData('text')
const TASK = document.getElementById(TASK_ID)
TASK.querySelector('.task__content').setAttribute('contenteditable', 'true')
if (destination) destination.appendChild(document.getElementById(TASK_ID))
}
window.ON_DRAG_START = e => {
if (!e.target.closest) return e.preventDefault()
const TASK = e.target.closest('.task')
TASK.querySelector('.task__content').removeAttribute('contenteditable')
TASK.id = new Date().toUTCString()
e.dataTransfer.dropEffect = 'copy'
e.dataTransfer.setDragImage(TASK, 0, 0)
e.dataTransfer.setData('text', TASK.id)
}
window.REMOVE_TASK = e =>
window.confirm('Remove task') && e.target.closest('.task').remove()
window.ADD_TASK = e => {
const TASKS = e.target.closest('.column').querySelector('.column__tasks')
const TASK = document.createElement('div')
TASKS.appendChild(TASK)
TASK.outerHTML = TASK_TEMPLATE`${prompt('What do you need to do?')}`
}
Also see: Tab Triggers