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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
.pac-input__wrap
.pac-input
input(data-lpignore="true" type='password' value='chomprulz' autocomplete="off")
a.pac-input__pac
a.pac-input__ghost
.pac-input__ghost-eyes
.pac-input__cloak
*
box-sizing border-box
:root
--bg hsl(211, 97%, 12%)
--input hsl(0, 0%, 60%)
--pac hsl(59, 100%, 50%)
--border hsl(231, 92%, 45%)
--border--hover hsl(231, 92%, 62%)
--border--active hsl(231, 92%, 52%)
--ghost--green hsl(181, 100%, 57%)
--ghost--pink hsl(332, 98%, 81%)
--ghost--orange hsl(48, 100%, 50%)
--ghost--red hsl(12, 100%, 47%)
--track--dot hsl(0, 0%, 98%)
--size 30px
--width 300px
--height 50px
--font 24px
--speed .25s
html
body
background var(--bg)
display flex
align-items center
justify-content center
min-height 100vh
width 100vw
font-family 'Arial', sans-serif
overflow hidden
.pac-input
position relative
overflow hidden
border 6px solid var(--border)
border-radius 8px
transition border-color 0.1
&__wrap
border-radius 8px
box-shadow 0 20px 20px -20px black
& > input
border 0
border-radius 0
font-size var(--font)
line-height var(--font)
padding 6px 45px 6px 12px
letter-spacing 1px
width var(--width)
height var(--height)
background var(--input)
&:focus
outline transparent
&__cloak
background-color $var(--input)
width 100%
height var(--size)
position absolute
top 50%
left 100%
transform translate(-24px, -50%)
&__ghost
cursor pointer
height var(--size)
width 100%
position absolute
right 105%
top 50%
width var(--size)
border-radius 100% 100% 0 0
position absolute
z-index 1
transform translate(0, -50%)
clip-path polygon(15% 100%, 0 85%, 0 0, 100% 0, 100% 85%, 85% 100%, 66% 85%, 50% 100%, 30% 85%)
-webkit-clip-path polygon(15% 100%, 0 85%, 0 0, 100% 0, 100% 85%, 85% 100%, 66% 85%, 50% 100%, 30% 85%)
&-eyes
height 6px
width 20px
position absolute
top 8px
left 5px
&:before
&:after
border-radius 100%
content ''
height 6px
width 6px
background radial-gradient(circle at 30% 60%, blue 0, blue 25%, white 25%, white 100%)
position absolute
&:after
left 8px
&__pac
cursor pointer
position absolute
top 50%
right 10px
height var(--size)
width var(--size)
transform translate(0, -50%)
z-index 1
&--chomping
&:before
animation-name chomp--1
&:after
animation-name chomp--2
&:before
&:after
content ''
position absolute
left 0
border-radius 100%
border calc(var(--size) / 2) solid var(--pac)
transform-origin center center
animation-duration var(--speed)
animation-timing-function linear
animation-iteration-count infinite
&:before
border-left-color transparent
border-bottom-color transparent
&:after
border-top-color transparent
border-right-color transparent
transform rotate(-90deg)
@keyframes chomp--1
0%, 100%
transform rotate(0deg)
50%
transform rotate(-45deg)
@keyframes chomp--2
0%, 100%
transform rotate(-90deg)
50%
transform rotate(-45deg)
const {
gsap: {
timeline,
set,
utils: { random },
},
} = window
const AUDIO = {
CLICK: new Audio('https://assets.codepen.io/605876/click.mp3'),
IN: new Audio('https://assets.codepen.io/605876/pac-in.mp3'),
OUT: new Audio('https://assets.codepen.io/605876/pac-out.mp3'),
}
const CONTAINER = document.querySelector('.pac-input')
const PAC = CONTAINER.querySelector('.pac-input__pac')
const GHOST = CONTAINER.querySelector('.pac-input__ghost')
const EYES = GHOST.querySelector('.pac-input__ghost-eyes')
const INPUT = CONTAINER.querySelector('input')
const CLOAK = CONTAINER.querySelector('.pac-input__cloak')
const COLORS = {
INPUT: 'hsl(0, 0%, 60%)',
BG: 'hsl(0, 0%, 0%)',
GHOST: ['orange', 'green', 'pink', 'red'],
}
const DURATIONS = {
ENV: 0.15,
CHOMP: 1,
GHOST: 1,
EYES: 0.5,
}
const BLINK = () => {
const delay = random(2, 6)
timeline().to(EYES, {
delay,
onComplete: () => BLINK(),
scaleY: 0.1,
repeat: 3,
yoyo: true,
duration: 0.05,
})
}
BLINK()
const hidePassword = () => {
timeline({
onStart: () => AUDIO.CLICK.play(),
onComplete: () => {
AUDIO.OUT.pause()
AUDIO.OUT.currentTime = 0
},
})
.to(GHOST, {
duration: DURATIONS.EYES,
right: '105%',
ease: 'none',
onStart: () => {
AUDIO.OUT.play()
set(GHOST, { backgroundColor: COLORS.INPUT })
},
})
.to(
CLOAK,
{
duration: DURATIONS.EYES,
onComplete: () => {
set(PAC, { right: 10, scale: 0 })
set(INPUT, { attr: { type: 'password' } })
},
left: -5,
ease: 'none',
},
0
)
.to(CLOAK, DURATIONS.ENV, {
duration: DURATIONS.ENV,
opacity: 0,
onComplete: () => {
set(CLOAK, { left: '100%', opacity: 1 })
},
})
.to(
PAC,
{
duration: DURATIONS.ENV,
scale: 1,
},
DURATIONS.EYES
)
}
const showPassword = () => {
timeline({
onStart: () => AUDIO.CLICK.play(),
onComplete: () => {
AUDIO.IN.pause()
AUDIO.IN.currentTime = 0
},
})
.to(INPUT, {
duration: DURATIONS.ENV,
onStart: () => {
set(GHOST, {
backgroundColor: `var(--ghost--${
COLORS.GHOST[Math.floor(Math.random() * COLORS.GHOST.length)]
})`,
})
},
letterSpacing: 15,
backgroundColor: COLORS.BG,
color: 'hsl(0, 0, 98%)',
})
.to(
CLOAK,
{
duration: DURATIONS.ENV,
backgroundColor: COLORS.BG,
},
0
)
.to(PAC, DURATIONS.CHOMP, {
duration: DURATIONS.CHOMP,
right: '105%',
ease: 'none',
onStart: () => {
AUDIO.IN.play()
PAC.classList.add('pac-input__pac--chomping')
},
onComplete: () => {
PAC.classList.remove('pac-input__pac--chomping')
set(INPUT, { attr: { type: 'text' } })
},
})
.to(
CLOAK,
{
duration: DURATIONS.CHOMP,
left: -5,
ease: 'none',
},
'<'
)
.to(GHOST, {
duration: DURATIONS.GHOST,
right: 10,
ease: 'none',
})
.to(
CLOAK,
{
duration: DURATIONS.GHOST,
left: '100%',
ease: 'none',
},
'<'
)
.to(INPUT, {
duration: DURATIONS.ENV,
letterSpacing: 1,
backgroundColor: COLORS.INPUT,
color: 'black',
})
.to(
CLOAK,
{
duration: DURATIONS.ENV,
backgroundColor: COLORS.INPUT,
},
'<'
)
}
PAC.addEventListener('click', showPassword)
GHOST.addEventListener('click', hidePassword)
Also see: Tab Triggers