Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                mixin balloon()
  svg.balloon(xmlns='http://www.w3.org/2000/svg' viewbox='0 0 117.9 124.8' style=`--s: ${Math.random() * 10 + 2}; --d: ${Math.random() * -10};`)
    path.balloon__string(d='M59 121v170' stroke-width='2.4')
    path.balloon__body(d='M59 0A59 59 0 000 59a59 59 0 0050 58 6 6 0 005 8h7a6 6 0 006-8 59 59 0 0050-58A59 59 0 0059 0z')
    path.balloon__glare(d='M14 42a45 45 0 0127-26' stroke-width='7.9' stroke-linecap='round' stroke-linejoin='round')
    path.balloon__shadow(d='M59 0a59 59 0 00-5 0 59 59 0 0157 59 59 59 0 01-58 59 59 59 0 01-3 0v1c0 3 2 6 5 6h7a6 6 0 006-8 59 59 0 0050-58A59 59 0 0059 0zm-5 0a59 59 0 00-6 1 59 59 0 016-1zm-6 1a59 59 0 00-6 2 59 59 0 016-2zm-6 2zm0 0a59 59 0 00-5 1 59 59 0 015-1zm-5 1a59 59 0 00-1 1 59 59 0 011-1zm-1 1a59 59 0 00-5 2 59 59 0 015-2zm-5 2zm0 0a59 59 0 00-5 3 59 59 0 015-3zm-5 3zm0 0a59 59 0 00-4 3 59 59 0 014-3zm-4 3a59 59 0 00-1 1 59 59 0 011-1zm-1 1a59 59 0 00-3 3 59 59 0 013-3zm-3 3a59 59 0 00-1 1 59 59 0 011-1zm-1 1a59 59 0 00-3 3 59 59 0 013-3zm-3 3a59 59 0 00-1 1 59 59 0 011-1zm-1 1a59 59 0 00-3 4 59 59 0 013-4zm-3 4a59 59 0 000 1 59 59 0 010-1zm0 1a59 59 0 00-3 4 59 59 0 013-4zm-3 4a59 59 0 000 1 59 59 0 010-1zm0 1a59 59 0 00-2 4 59 59 0 012-4zm-2 4a59 59 0 00-1 1 59 59 0 011-1zm-1 1a59 59 0 00-1 4 59 59 0 011-4zm-1 4a59 59 0 00-1 2 59 59 0 011-2zm-1 2a59 59 0 00-1 3 59 59 0 011-3zm-1 3a59 59 0 000 3 59 59 0 010-3zm0 3a59 59 0 00-1 3 59 59 0 011-3zm-1 3a59 59 0 000 3 59 59 0 010-3zm0 3a59 59 0 000 4 59 59 0 010-4z')

mixin cake(face, candles)
  svg.cake(class!=attributes.class xmlns='http://www.w3.org/2000/svg' viewBox='0 0 105.8 45.4' preserveAspectRatio="none")
    path.cake__body(d='M0 0h106v45H0z')
    path.cake__frosting(d='M1-8h104c4 0 8 4 8 9s-4 8-8 9c-5 0-8-8-13-8s-8 8-13 8-8-8-13-8-8 8-13 8-8-8-13-8-8 8-13 8-8-8-13-8-8 8-13 8c-4-1-8-4-8-9s3-9 8-9z' fill='purple')
    if (face)
      g.cake__face
        g.cake__eyes
          g(transform='translate(-8 -237)')
            circle(cx='38.6' cy='259.2' r='4.5')
            circle(cx='36.3' cy='257.1' r='.8' fill='#fff')
          g(transform='translate(37 -237)')
            circle(r='4.5' cy='259.2' cx='38.6')
            circle(r='.8' cy='257.1' cx='36.3' fill='#fff')
        g.cake__mouth
          path(d='M57 25a4 4 0 11-8 0')
          path(d='M55 26a3 3 0 00-3 2 4 4 0 004-1 3 3 0 00-1-1z' fill='red')
        g.cake__cheeks(transform='translate(-13 -237)' fill='#ffd5d5')
          circle(r='3.7' cy='265.5' cx='28.6')
          circle(cx='102.9' cy='265.5' r='3.7')
    if (candles)
      g.cake__candle
        g(transform='translate(-13 -238)')
          rect.candle__body(ry='0' y='212.2' x='34.2' height='21.8' width='6.8')
          path.candle__stripes(d='M34 224v3l7 7v-3zM34 218v4l7 6v-3zM34 212v4l7 7v-4z')
        g.candle__flame
          path.candle__flame-outer(d='M29-30a4 4 0 01-8 0c0-2 4-2 4-7s4 5 4 7z')
          path.candle__flame-inner(d='M27-29a2 2 0 01-4-1c0-1 2-1 2-3 1-2 2 3 2 4z')
      g.cake__candle
        g(transform='translate(43 -238)')
          rect.candle__body(width='6.8' height='21.8' x='34.2' y='212.2' ry='0')
          path.candle__stripes(d='M34 224v3l7 7v-3zM34 218v4l7 6v-3zM34 212v4l7 7v-4z')
        g.candle__flame
          path.candle__flame-outer(d='M85-29a4 4 0 01-8 0c0-3 4-3 4-7 0-6 4 4 4 7z')
          path.candle__flame-inner(d='M83-29a2 2 0 01-4-1c0-1 2 0 2-3 1-2 2 3 2 4z')
      g.cake__candle
        g(transform='translate(15 -232)')
          rect.candle__body(width='6.8' height='21.8' x='34.2' y='212.2' ry='0')
          path.candle__stripes(d='M34 224v3l7 7v-3zM34 218v4l7 6v-3zM34 212v4l7 7v-4z')
        g.candle__flame
          path.candle__flame-outer(d='M57-24a4 4 0 01-8 0c0-2 4-2 4-7s4 5 4 7z')
          path.candle__flame-inner(d='M55-24a2 2 0 01-4 0c0-1 2-1 2-3 1-2 2 2 2 3z')
    g.cake__sprinkles
      g(transform='translate(-10 -237)')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` transform='rotate(39)' ry='1.2' y='199.6' x='185.8' height='6.3' width='2.4')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` width='2.4' height='6.3' x='-141.5' y='236.8' ry='1.2' transform='rotate(-36)')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` transform='rotate(-72)' ry='1.2' y='185.1' x='-231.3' height='6.3' width='2.4')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` width='2.4' height='6.3' x='220' y='190.4' ry='1.2' transform='rotate(30)')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` transform='rotate(46)' ry='1.2' y='128.8' x='257.6' height='6.3' width='2.4')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` width='2.4' height='6.3' x='-186.3' y='216.6' ry='1.2' transform='rotate(-56)')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` transform='rotate(30)' ry='1.2' y='212.4' x='178.7' height='6.3' width='2.4')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` width='2.4' height='6.3' x='-191.8' y='199.2' ry='1.2' transform='rotate(-51)')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` transform='rotate(77)' ry='1.2' y='-7.4' x='284.7' height='6.3' width='2.4')
        rect.cake__sprinkle(style=`--hue: ${Math.random() * 359}` width='2.4' height='6.3' x='-218.9' y='174.7' ry='1.2' transform='rotate(-63)')

input#read(type="checkbox")
label(for="read") Read Card
.scene
  .card
    - let c = 0
    while c < 50
      .card__confetti(style=`--rx: ${Math.random() * 360}; --ry: ${Math.random() * 360}; --a: ${Math.random() * 90}; --hue: ${Math.random() * 360}; --r: ${Math.random() * 180 - 90}; --s:${Math.random() * 5}; --sk: ${Math.random() * 20};`)
      - c++
    .card__outer.card__part.flip
      .flip__piece.flip__piece--front.section
        .section__piece.section__piece--front.front-cover.front-cover__front
        .section__piece.section__piece--rear.front-cover.hide-back
          .cover__content.cover__content--front.hide-back
            h1.message.hide-back
              span Happy
              span Birthday!
            +balloon()
            +balloon()
            +balloon()
      .flip__piece.flip__piece--back.section
        .section__piece.section__piece--front.rear-cover.rear-cover__front
        .section__piece.section__piece--back.hide-back
          .cover__content.cover__content--rear
            .barcode
            img.stamp(src="https://assets.codepen.io/605876/avatar.png" alt="jh3y avatar")
    .card__inner.card__part.flip
      .flip__piece.flip__piece--front.section
        .section__piece.section__piece--back.inner-top
          .card__content-container.card__content-container--inner-top
            .card__content.card__content--top
              .cake__section.cake__section--bottom.cake__section--bottom-top
                .cake__section.cake__section--mid-top.cake__section--mid
                  .cake__section.cake__section--top-top.cake__section--top
                  .cake__section.cake__section--top-front.cake__section--top
                    +cake(false, true)(class="cake--top")
                .cake__section.cake__section--mid-front.cake__section--mid
                  +cake(false, false)(class="cake--mid")
      .flip__piece.flip__piece--back.section
        .section__piece.section__piece--front.inner-bottom
          .card__content-container.card__content-container--inner-bottom
            .card__content.card__content--bottom
              .cake__section.cake__section--bottom-front.cake__section--bottom
                +cake(true, false)(class="cake--bottom")
              h2.card__message Eat some cake!
svg
  filter#scribble--0
    feturbulence(basefrequency='0.02', numoctaves='3', result='noise', seed='0')
    fedisplacementmap#displacement(in='SourceGraphic', in2='noise', scale='2')
  filter#scribble--1
    feturbulence(basefrequency='0.02', numoctaves='3', result='noise', seed='1')
    fedisplacementmap(in='SourceGraphic', in2='noise', scale='3')
  filter#scribble--2
    feturbulence(basefrequency='0.02', numoctaves='3', result='noise', seed='2')
    fedisplacementmap(in='SourceGraphic', in2='noise', scale='2')
  filter#scribble--3
    feturbulence(basefrequency='0.02', numoctaves='3', result='noise', seed='3')
    fedisplacementmap(in='SourceGraphic', in2='noise', scale='3')
  filter#scribble--4
    feturbulence(basefrequency='0.02', numoctaves='3', result='noise', seed='4')
    fedisplacementmap(in='SourceGraphic', in2='noise', scale='2')
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Fredoka+One&display=swap')
*
  box-sizing border-box
  // transform-style preserve-3d


:root
  --bg hsl(210, 32%, 24%)
  --body hsl(0, 0%, 100%)
  --stripes hsl(10, 80%, 80%)
  --flame-1 hsl(30, 80%, 60%)
  --flame-2 hsl(45, 90%, 80%)
  --paper hsl(210, 80%, 85%)
  --paper-2 hsl(210, 80%, 95%)
  --paper-3 hsl(210, 80%, 60%)
  --card hsl(0, 0%, 98%)
  --insert hsl(210, 80%, 85%)
  --bottom-frosting hsl(10, 80%, 80%)
  --mid-frosting hsl(180, 80%, 80%)
  --top-frosting hsl(90, 80%, 80%)
  --balloon-3 10
  --balloon-2 180
  --balloon-1 90
  --size 35vmin
  --height var(--size)
  --width calc(var(--size) * 1.4)
  --read 0
  --transition 0.2s

body
  background var(--bg)
  min-height 100vh
  perspective 1000px
  transform-style preserve-3d
  overflow hidden

input
  opacity 0
  position fixed
  right 100%

label
  height 100vh
  width 100vw
  position fixed
  top 0
  left 0
  z-index 2
  transform-style preserve-3d
  transform translate3d(0, 0, 100px)

:checked ~ .scene
  --read 1

  .hide-back
    -webkit-backface-visibility hidden
    backface-visibility hidden

  .cake__candle
    transform translate(0, 0)

.stamp
  height 8vmin
  position absolute
  top 50%
  left 50%
  transform translate3d(-50%, -50%, 1px)
  filter saturate(0.5)

.barcode
  height 6vmin
  width 8vmin
  position absolute
  bottom 2vmin
  right 2vmin
  transform translate3d(0, 0, 1px)
  --l hsl(0, 0%, 50%)
  background repeating-linear-gradient(90deg, var(--l) 0 1%, transparent 1% 2%, var(--l) 2% 4%, transparent 4% 5%, var(--l) 5% 10%)

.scene
  display flex
  align-items center
  justify-content center
  transform rotateY(calc(var(--x, 0) * 1deg)) rotateX(calc(var(--y, 0) * 1deg))
  height 100vh
  width 100vw
  transform-style preserve-3d

.card
  height calc(var(--height))
  position relative
  width var(--width)
  transform-style preserve-3d
  transform translate(0, calc(var(--read, 0) * 25%)) rotateX(calc(var(--read, 0) * 90deg))
  transition transform var(--transition)

  &__confetti
    --size calc(var(--s) * 1vmin)
    height var(--size)
    width var(--size)
    position absolute
    top 0%
    left 50%
    transition transform calc(var(--read) * var(--transition)) calc(var(--read) * var(--transition)), opacity calc(var(--read) * var(--transition)) calc((var(--read) * var(--transition)) * 2)
    transform scale(var(--read)) translate(-50%, 10%) rotate(calc(var(--r) * 1deg)) rotateX(calc(var(--a) * 1deg)) skew(calc(var(--sk) * 1deg)) translate(0, calc(var(--height) * (var(--read, 0) * 1.5)))
    opacity calc(1 - var(--read))

    &:after
      background 'hsl(%s, 80%, 80%)' % var(--hue)
      content ''
      position absolute
      height 100%
      width 100%
      transition transform calc(var(--read) * var(--transition)) calc(var(--read) * var(--transition))
      transform rotateX(calc((var(--rx) * var(--read)) * 1deg)) rotateY(calc((var(--ry) * var(--read)) * 1deg))

  &__content
    transform-style preserve-3d
    height 100%
    width 100%
    &--bottom
      // transform-style preserve-3d
      &:before
        content ""
        position absolute
        top 0
        left 0
        height 100%
        width 100%
        background var(--insert)
        $clip = polygon(0 0, 15% 0, 15% 30%, 85% 30%, 85% 0, 100% 0, 100% 100%, 0 100%)
        -webkit-clip-path $clip
        clip-path $clip
    &--top
      // transform-style preserve-3d
      &:before
        content ""
        position absolute
        top 0
        left 0
        height 100%
        width 100%
        background var(--insert)
        $clip = polygon(0 0, 100% 0, 100% 100%, 85% 100%, 85% 70%, 78% 70%, 78% 46%, 72.4% 46%, 72.4% 26.8%, 27.6% 26.8%, 27.6% 46%, 22% 46%, 22% 70%, 15% 70%, 15% 100%, 0 100%)
        -webkit-clip-path $clip
        clip-path $clip

  &__message
    position absolute
    padding 1rem
    font-family sans-serif
    bottom 0
    left 50%
    transform translate(-50%, 0)

  &__part
    height var(--h, 100%)
    width var(--w, 100%)
    position absolute
    top 0%
    left 50%
    transform translate(-50%, 0)
    transform-style preserve-3d

  &__inner
    --h 96%
    --w 95%
    transform translate3d(-50%, 0, calc(var(--height) * 0))

  &__sleeve
    height 100%
    width 100%

.message
  font-family "Fredoka One", cursive
  color hsl(0, 0%, 10%)
  display flex
  flex-direction column
  position absolute
  top 50%
  left 20%
  transform translate3d(0, -50%, 0)
  margin 0
  font-size 4.5vmin

.card__message
  font-family "Fredoka One", cursive
  color hsl(0, 0%, 10%)
  font-size 4vmin
  white-space nowrap
  position absolute
  top 50%
  left 50%
  transform translate(-50%, 0)

.flip
  transform-style preserve-3d

  &__piece
    height 100%
    position absolute
    width 100%
    transform-origin 50% 0
    transform-style preserve-3d
    transition transform var(--transition)

    &--front
      transform rotateX(calc(var(--front) * 1deg))
    &--back
      transform rotateX(calc(var(--rear) * 1deg))

.card__inner
  // Either 1.75 or 89.75
  --rear calc(-1.75 + (var(--read, 0) * 2))
  --front calc(1.75 + (var(--read, 0) * 88))

.card__outer
  --rear calc(-2 + (var(--read, 0) * 2))
  --front calc(2 + (var(--read, 0) * 88))

.card__content-container
  transform-style preserve-3d
  height 100%
  width 100%
  top 0
  left 0
  position absolute
  &--inner-top
    transform rotate(180deg) translate3d(0, 0, 0)
  &--inner-bottom
    transform translate3d(0, 0, 0)

.cover__content
  height 100%
  width 100%
  background var(--card)
  position absolute
  font-size 2vmin
  transform-style preserve-3d

  &--front
  &--rear
    transform translate3d(0, 0, 1px)

.front-cover__front
.rear-cover__front
  background var(--card)

.front-cover__front:after
.rear-cover__front:after
  content ''
  position absolute
  top 0%
  left 50%
  transform translate3d(-50%, 0, 0px)
  background var(--paper-3)
  height 95%
  width 95%
.rear-cover__front:after
  transform translate(-50%, 0, 2px)

.cake__section
  position absolute
  transform-style preserve-3d
  transition var(--transition)

  &--top
    height 80%
    width 80%
    left 50%
    bottom 0

    &-top
      transform translate(-50%, 0) rotateX(calc(var(--read, 0) * 90deg)) translate3d(0, -100%, calc(var(--read, 0) * 0px)) rotateX(calc(var(--read, 0) * -90deg))
      transform-origin 50% 100%
      background var(--paper)
    &-front
      background var(--paper-2)
      transform-origin 50% 100%
      transform translate(-50%, -100%) rotateX(calc(var(--read, 0) * 90deg))

  &--mid
    height 80%
    width 80%
    left 50%

    &-front
      bottom 0
      transform-origin 50% 0
      transform translate3d(-50%, 0, 0) rotateX(calc((180 - (var(--read, 0) * -90)) * 1deg))
      background var(--paper-2)

    &-top
      background transparent
      bottom 0
      transform-origin 50% 100%
      transform translate(-50%, 0) rotateX(calc(var(--read, 0) * 90deg)) translate3d(0, -100%, calc(var(--read, 0) * 0px)) rotateX(calc(var(--read, 0) * -90deg))

      &:before
        content ''
        position absolute
        height 100%
        width 100%
        $clip = polygon(0 0, 10% 0, 10% 80%, 90% 80%, 90% 0, 100% 0, 100% 100%, 0 100%)
        -webkit-clip-path $clip
        clip-path $clip
        transform rotate(180deg)
        background var(--paper)

  &--bottom
    height 30%
    width 70%
    left 50%
    transition var(--transition)

    &-top
      background transparent
      transform-origin 50% 100%
      bottom 0
      transform translate(-50%, -100%) rotateX(calc(var(--read, 0) * -90deg))

      &:before
        content ''
        position absolute
        height 100%
        width 100%
        $clip = polygon(0 0, 10% 0, 10% 80%, 90% 80%, 90% 0, 100% 0, 100% 100%, 0 100%)
        -webkit-clip-path $clip
        clip-path $clip
        transform rotate(180deg)
        background var(--paper)

    &-front
      background var(--paper-2)
      top 0
      transform-origin 50% 0
      transform translate(-50%, 100%) rotateX(calc(var(--read, 0) * 90deg))

.section
  height 100%
  width 100%

  &__piece
    position absolute
    height 100%
    width 100%
    transform-style preserve-3d

    &--back
      transform rotateY(180deg)

.balloon
  overflow visible !important
  height 6vmin
  position absolute
  left calc(var(--x, 0) * 1%)
  top calc(var(--y, 0) * 1%)
  animation float calc(var(--s, 0) * 1s) calc(var(--d, 0) * 1s) infinite

  &__body
    fill 'hsla(%s, 80%, 50%, 0.75)' % var(--hue, 0)

  &__glare
    fill hsla(0, 0%, 100%, 0.75)

  &__shadow
    fill 'hsla(%s, 80%, 30%, 0.75)' % var(--hue, 0)

  &__string
    stroke hsl(40, 40%, 50%)

  &:nth-of-type(1)
    --hue var(--balloon-1)
    --x 58
    --y 28
  &:nth-of-type(2)
    --hue var(--balloon-2)
    --x 68
    --y 20
  &:nth-of-type(3)
    --hue var(--balloon-3)
    --x 65
    --y 40

.cake
  overflow visible !important
  width 100%
  height 100%
  transform translate3d(0, 0, 1px)

  &__frosting
    fill var(--frosting)

  &__eyes
    transform-origin 50% 24px
    animation blink 5s infinite

  &__body
    fill var(--body)

  &--bottom
    --frosting var(--bottom-frosting)
  &--mid
    --frosting var(--mid-frosting)
  &--top
    --frosting var(--top-frosting)

  &--bottom
  &--mid
    transform translate3d(0, 0, -1px) rotate(180deg)

  &--mid
  &--top
    .cake__sprinkles
      transform translate(0, -8px)

  &__candle
    transform translate(0, 12px)
    transition var(--transition)


  &__sprinkle
    fill 'hsl(%s, 80%, 70%)' % var(--hue)

.candle
  &__body
    fill var(--body)
  &__stripes
    fill var(--stripes)
  &__flame
    animation scribble 0.5s infinite
  &__flame-outer
    fill var(--flame-1)
  &__flame-inner
    fill var(--flame-2)

@keyframes blink
  0%, 47%, 49%, 51%, 100%
    transform scaleY(1)
  48%, 50%
    transform scaleY(0.1)


@keyframes float
  0%, 100%
    transform translate3d(0, 0, calc(var(--s) * 1px))
  50%
    transform translate3d(0, -25%, calc(var(--s) * 1px))

@keyframes scribble
  0%
    filter url('#scribble--0')
  25%
    filter url('#scribble--1')
  50%
    filter url('#scribble--2')
  75%
    filter url('#scribble--3')
  100%
    filter url('#scribble--4')
              
            
!

JS

              
                const mapRange = (a1, a2, b1, b2, value) => {
  const inRange = a2 - a1
  const outRange = b2 - b1
  const func = v => b1 + (((v - a1) / inRange) * outRange || 0)
  return value || value === 0 ? func(value) : func
}

const BOUNDS = 90
const UPDATE = ({ x: pointerX, y: pointerY }) => {
  const x = mapRange(0, window.innerWidth, -BOUNDS, BOUNDS, pointerX)
  const y = mapRange(0, window.innerHeight, BOUNDS, -BOUNDS, pointerY)
  document.documentElement.style.setProperty('--x', x)
  document.documentElement.style.setProperty('--y', y)
}
const CHEER = new Audio('https://assets.codepen.io/605876/kids-cheering.mp3')
CHEER.volume = 0.5
const INPUT = document.querySelector('input')
INPUT.addEventListener('change', () => {
  if (INPUT.checked) {
    CHEER.currentTime = 0
    CHEER.play()
  }
})

window.addEventListener('pointermove', UPDATE)

              
            
!
999px

Console