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="notifications"></div>9
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
:root {
font-family: "Inter";
font-size: 16px;
--gradient: linear-gradient(to bottom, #2eadff, #3d83ff, #7e61ff);
--color: #32a6ff
}
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
margin: 0;
height: 100vh;
width: 100%;
background: #0c0c0b;
overflow: hidden;
display: flex;
justify-content: center;
}
.notifications {
width: 18rem;
display: flex;
flex-direction: column;
justify-content: end;
margin: 0.5rem;
}
.noti {
position: relative;
height: 0;
transition: height 300ms ease;
flex-shrink: 0;
opacity: 1;
}
.noti.out {animation: notiOut 500ms ease forwards}
@keyframes notiOut {
to {height: 0;}
}
.noticard {
position: absolute;
bottom: 0;
display: flex;
flex-direction: column;
isolation: isolate;
width: 18rem;
d-height: 8rem;
background: #29292c;
border-radius: 1rem;
overflow: hidden;
animation: notiCardIn 500ms ease;
}
@keyframes notiCardIn {
from {
transform: translateX(50%);
opacity: 0;
}
}
.noti.out .noticard {animation: notiCardOut 500ms ease forwards}
@keyframes notiCardOut {
to {
opacity: 0;
transform: scale(0.5)
}
}
.noticard:before {
position: absolute;
content: "";
inset: 0.0625rem;
border-radius: 0.9375rem;
background: #18181b;
z-index: 2
}
.noticard:after {
position: absolute;
content: "";
width: 0.25rem;
inset: 0.65rem auto 0.65rem 0.5rem;
border-radius: 0.125rem;
background: var(--gradient);
transition: transform 300ms ease;
z-index: 4;
}
.noticard:hover:after {
transform: translateX(0.15rem)
}
.notititle {
color: var(--color);
padding: 0.65rem 0.5rem 0.4rem 1.25rem;
font-weight: 500;
font-size: 1.1rem;
transition: transform 300ms ease;
z-index: 5;
}
.noti:hover .notititle {
transform: translateX(0.15rem)
}
.notidesc {
color: #99999d;
padding: 0 0.5rem 0.85rem 1.25rem;
transition: transform 300ms ease;
z-index: 5;
}
.noti:hover .notidesc {
transform: translateX(0.25rem)
}
.notiglow, .notiborderglow {
position: absolute;
width: 20rem;
height: 20rem;
transform: translate(-50%, -50%);
background: radial-gradient(circle closest-side at center, white, transparent);
opacity: 0;
transition: opacity 300ms ease;
}
.notiglow { z-index: 3; }
.notiborderglow { z-index: 1; }
.noti:hover .notiglow {opacity: 0.1}
.noti:hover .notiborderglow {opacity: 0.1}
// if the pen is in thumbnail view, scale it up
if (location.pathname.match(/fullcpgrid/i) ? true : false) {
document.documentElement.style.fontSize = "32px"
document.querySelector(".notifications").style.transform = "translate(0.5rem, calc(-50% + 3rem))"
}
class Notifications {
constructor(el) {
this.el = el
}
// function to create new elements with a class (cleans up code)
createDiv(className = "") {
const el = document.createElement("div")
el.classList.add(className)
return el
}
// function to add text nodes to elements
addText(el, text) {
el.appendChild(document.createTextNode(text))
}
create(
title = "Untitled notification",
description = "",
duration = 2,
destroyOnClick = false,
clickFunction = undefined
) {
// functions
function destroy(animate) {
if (animate) {
notiEl.classList.add("out")
notiEl.addEventListener("animationend", () => {notiEl.remove()})
} else {
notiEl.remove()
}
}
// create the elements and add their content
const notiEl = this.createDiv("noti")
const notiCardEl = this.createDiv("noticard")
const glowEl = this.createDiv("notiglow")
const borderEl = this.createDiv("notiborderglow")
const titleEl = this.createDiv("notititle")
this.addText(titleEl, title)
const descriptionEl = this.createDiv("notidesc")
this.addText(descriptionEl, description)
// append the elements to each other
notiEl.appendChild(notiCardEl)
notiCardEl.appendChild(glowEl)
notiCardEl.appendChild(borderEl)
notiCardEl.appendChild(titleEl)
notiCardEl.appendChild(descriptionEl)
this.el.appendChild(notiEl)
// transition the height of the container to the height of the visible card
console.log("height", notiCardEl.scrollHeight)
requestAnimationFrame(function() {
notiEl.style.height = "calc(0.25rem + " + notiCardEl.getBoundingClientRect().height + "px)";
});
// hover animation
notiEl.addEventListener("mousemove", (event) => {
const rect = notiCardEl.getBoundingClientRect()
const localX = (event.clientX - rect.left) / rect.width
const localY = (event.clientY - rect.top) / rect.height
console.log(localX, localY)
glowEl.style.left = localX * 100 + "%"
glowEl.style.top = localY * 100 + "%"
borderEl.style.left = localX * 100 + "%"
borderEl.style.top = localY * 100 + "%"
});
// onclick function if one is set
if (clickFunction != undefined) {
notiEl.addEventListener("click", clickFunction)
}
// destroy the notification on click if it is set to do so
if (destroyOnClick) {
notiEl.addEventListener("click", () => destroy(true))
}
// remove the notification after the set time if there is one
if (duration != 0) {
setTimeout(() => {
notiEl.classList.add("out")
notiEl.addEventListener("animationend", () => {notiEl.remove()})
}, duration * 1000)
}
return notiEl
}
}
// demo
notis = new Notifications(document.querySelector(".notifications"))
const demonotis = [
() => {notis.create("Neon notifications", "wow, these notifications really do look beautiful", 5)},
() => {notis.create("Hover effects", "and the hover effects make it even better!", 5)},
() => {notis.create("Ease of use", "on top of that, you can easily add this to any project", 10)},
() => {notis.create("Customisation", "you can even customise the duration and add actions on click", 10)},
() => {notis.create("Click me", "try clicking this for a surprise!", 5, true, () => notis.create("Surprise", "Wow, you clicked the previous notification,", 4))},
() => {notis.create("Animations", "all the animations stay smooth even when notifications disappear out of order or when multiple appear at once", 15)},
]
let i = 1;
demonotis[0]()
setInterval(()=>{
if (i == demonotis.length) {
notis.create("Demo done", "click on this notification to restart the demo or go look at the code if you're interested", 0, true, () => {i = 0})
} else if (i < demonotis.length) {
demonotis[i]()
}
i++
}, 4000)
/*
How to use:
create the notification object using new Notifications and pass it the notification wrapper element
ex: const notis = new Notifications(document.querySelector(".notifications"))
make notifications by using notis.create() (or *.create() if you named it something else)
notis.create() parameters:
Title: string,
Description: string,
Duration: seconds (default: 2s, 0 makes it stay forever),
Destroy on click: boolean
(determines if the notification should disappear when clicked, default: false)
Click function: function
(gets called when the notification is clicked if it isnt undefined, default: undefined)
*/
Also see: Tab Triggers