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 class="window">
<aside>
<nav>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</nav>
<div class="aside-content">
<details open>
<summary>Favorite</summary>
<ul>
<li>Recent</li>
<li>Yexan</li>
<li>Images</li>
<li>Documents</li>
<li>Apps</li>
<li class="active">Desktop</li>
<li>Downloads</li>
</ul>
</details>
<details open>
<summary>Connected</summary>
<ul>
<li>Network</li>
<li>Hard Drive</li>
<li>Hard Drive</li>
</ul>
</details>
</div>
</aside>
<main>
<nav>
Desktop
</nav>
<div class="main-content">
</div>
</main>
</div>
.window
position: fixed
top: 70px
left: 120px
width: 650px
height: 350px
display: grid
grid-template-columns: 200px 1fr
border-radius: 10px
box-shadow: 5px 5px 25px -2px rgba(0,0,0,.4)
overflow: auto
aside
position: relative
padding: 0
margin: 0
backdrop-filter: blur(25px)
nav
position: absolute
top: 0
left: 0
right: 0
padding: 20px 15px
z-index: 2
cursor: move
ul
display: flex
flex-direction: row
align-items: center
justify-content: flex-start
li
width: 13px
height: 13px
padding: 0
border-radius: 10px
cursor: pointer
&:before
background: none
& + li
margin-left: 10px
&:nth-child(1)
background: #E53935
&:nth-child(2)
background: #FFCA28
&:nth-child(3)
background: #8BC34A
.aside-content
position: absolute
top: 50px
bottom: 0
left: 0
right: 0
padding: 0px 15px 15px
overflow: auto
details
& + details
margin-top: 15px
summary
margin-bottom: 2px
font-size: .85em
font-weight: bold
color: rgba(0, 0, 0, .7)
cursor: pointer
ul
margin: 0
padding: 0 0 0 5px
list-style: none
li
position: relative
padding: 5px 0 5px 35px
color: rgba(255, 255, 255, .8)
border-radius: 5px
cursor: pointer
&.active
background: rgba(255, 255, 255, .1)
&:before
content: ''
position: absolute
top: 4px
left: 8px
width: 20px
height: 20px
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 298.757 298.757'%3E%3Cpath fill='%2357F' d='M291.701,119.091h-39.95v-29.61c0-3.893-3.156-7.05-7.05-7.05h-95.549l-16.896-35.955 c-1.162-2.472-3.648-4.051-6.381-4.051H7.05c-3.893,0-7.05,3.157-7.05,7.05v199.806c0,3.846,3.135,7.051,7.054,7.051 c0.004,0,0.008-0.001,0.012-0.001h237.635c2.923,0,5.543-1.805,6.587-4.536l47-123.14 C300.048,124.044,296.635,119.091,291.701,119.091z M14.1,56.526h107.299l16.896,35.955c1.162,2.472,3.648,4.051,6.381,4.051 h92.975v22.56H54.05c-2.923,0-5.544,1.805-6.587,4.536L14.1,211.04V56.526z M239.846,242.231H17.287l41.618-109.04 c10.158,0,212.404,0,222.559,0L239.846,242.231z'/%3E%3C/svg%3E") no-repeat
background-size: 90%
main
position: relative
padding: 0
margin: 0
nav
position: absolute
top: 0
left: 0
right: 0
display: flex
flex-direction: row
align-items: center
padding: 0 20px
height: 50px
color: rgba(255, 255, 255, .8)
background: rgba(20, 20, 20, 1)
z-index: 2
cursor: move
.main-content
position: absolute
top: 50px
bottom: 0
left: 0
right: 0
padding: 0px 15px 15px
background: rgba(10, 10, 10, .95)
overflow: auto
body
height: 100vh
margin: 0
padding: 0
font-family: Arial
background-image: url('https://images.unsplash.com/photo-1653579636217-0a062a1390ed?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2940&q=80')
background-size: cover
background-position: center
background-repeat: no-repeat
let pos1 = 0
let pos2 = 0
let pos3 = 0
let pos4 = 0
// Draggalbe window element
const win = document.querySelector('.window')
const dragMouseDown = (evt: MouseEvent) => {
evt = evt || window.event
evt.preventDefault()
pos3 = evt.clientX
pos4 = evt.clientY
document.onmouseup = closeDragElement
document.onmousemove = elementDrag
}
const elementDrag = (evt: MouseEvent) => {
evt = evt || window.event
evt.preventDefault()
pos1 = pos3 - evt.clientX
pos2 = pos4 - evt.clientY
pos3 = evt.clientX
pos4 = evt.clientY
win.style.top = (win.offsetTop - pos2) + 'px'
win.style.left = (win.offsetLeft - pos1) + 'px'
}
const closeDragElement = () => {
document.onmouseup = null
document.onmousemove = null
}
// Grabbed element allowed to move the window
const asideNav = document.querySelector('.window aside nav')
const mainNav = document.querySelector('.window main nav')
asideNav.onmousedown = dragMouseDown
mainNav.onmousedown = dragMouseDown
Also see: Tab Triggers