Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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 showNext(index)
  label(for=`movie-${index + 1}`) Next
  input(type="radio", id=`movie-${index + 1}`, name="next")
  - var nextMovie = movies[index + 1];
  if !nextMovie
    .congrats
      p Congratulations! πŸŽ‰ You did great πŸ‘
  else
    +movieWrapper(++index)

mixin movieInputs(index)
  - var currentMovie = movies[index];
  - var currentTitle = currentMovie.title;
  .container
    - for (var i = 0; i < currentTitle.length; i++)
      if currentTitle[i] === ' '
        .space
      else
        input.letter(
          type="text",
          required,
          maxlength="1", pattern=`^[${currentTitle[i].toLowerCase()}${currentTitle[i].toUpperCase()}]{1}$`
        )
    .space
    +showNext(index)

mixin movieWrapper(index)
  - var currentMovie = movies[index];
  - var movieId = currentMovie.title.toLowerCase().replace(' ', '-');
  if index === 0
    input(type="radio", id=`movie-${index}`, name="next", checked) 
  div(id=`${movieId}`, class=`movie movie-${index}`) 
    h2 #{currentMovie.hint}
    +movieInputs(index)
    
- var movies = [{ hint: 'πŸ‘¦πŸ»πŸ‘“βš‘οΈ', title: 'Harry Potter'}, { hint: 'β­πŸ’£βš”οΈ', title: 'Star Wars'}, { hint: 'πŸŒƒπŸ›οΈπŸ‘¨πŸ”¦πŸ—ΏπŸ™‰', title: 'Night at The Museum'}, { hint: 'πŸ‘΄βž‘οΈπŸ‘¨βž‘οΈπŸ‘¦βž‘οΈπŸ‘Ά',  title: 'The Curious Case of Benjamin Button'}, { hint: 'πŸ‘ΈπŸΏπŸΈπŸ’‹', title: 'The Princess and the Frog'}, { hint: 'πŸ€πŸ³πŸ½οΈπŸ—Ό', title: 'Ratatouille'}, { hint: '🐼πŸ₯‹πŸ‘Š', title: 'Kung Fu Panda'}, { hint: 'πŸ˜ˆπŸ‘—πŸ‘ ', title: 'The Devil Wears Prada'}, { hint: 'πŸ‘¦βœ‚οΈπŸ‘', title: 'Edward Scissorhands'}, { hint: 'πŸˆπŸ‘’', title:'Puss In Boots'}, { hint: '🀫🐐🐐', title: 'The Silence of the Lambs'}, { hint: 'πŸŒ—πŸ§›β€β™‚οΈπŸ’‘πŸΊ', title: 'Twilight'}, { hint: 'πŸ‘‘πŸŽ€πŸ’¬', title: "The King's Speech"}, { hint: 'πŸ‘¨πŸ«πŸ­', title: 'Charlie and the Chocolate Factory'}, { hint: 'πŸ‘¨πŸΌπŸ”¨βš‘', title: 'Thor'}, { hint: 'πŸ‘ΈπŸΌπŸ‘ πŸ•›', title: 'Cinderella'}, { hint: 'πŸŒπŸ’πŸ΅πŸ™‰', title: 'Planet of the Apes'}, { hint: 'πŸŒ΄πŸ’ƒπŸΌπŸ•ΊπŸΌπŸŽ₯🎹', title: 'La La Land'}, { hint: 'πŸ β“', title: 'Finding Nemo' }, { hint: 'πŸŒŒπŸ€ΎπŸΏβ€β™‚οΈπŸ°πŸ·πŸ₯', title: 'Space Jam'}];

.game-container
  header.wrapper
    h1 Guess the movie
    p
      small A HTML + CSS mini game
  main.levels.wrapper
    - var index = 0;
    +movieWrapper(index)
  footer.wrapper
    p 
      small This is an experimental mini game made with HTML and CSS only (no Javascript involved). All the logic is handled by HTML input elements and the `:checked` and `:valid` pseudo-classes in CSS


              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap");

$number-of-movies: 20;

*,
*::after,
*::before {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  text-align: center;
  background-color: #C8E6C9;
  // background image from Hero Patterns
  background-image: url('data:image/svg+xml,%3Csvg width="52" height="26" viewBox="0 0 52 26" xmlns="http://www.w3.org/2000/svg"%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cg fill="%239C92AC" fill-opacity="0.25"%3E%3Cpath d="M10 10c0-2.21-1.79-4-4-4-3.314 0-6-2.686-6-6h2c0 2.21 1.79 4 4 4 3.314 0 6 2.686 6 6 0 2.21 1.79 4 4 4 3.314 0 6 2.686 6 6 0 2.21 1.79 4 4 4v2c-3.314 0-6-2.686-6-6 0-2.21-1.79-4-4-4-3.314 0-6-2.686-6-6zm25.464-1.95l8.486 8.486-1.414 1.414-8.486-8.486 1.414-1.414z" /%3E%3C/g%3E%3C/g%3E%3C/svg%3E');
  color: hsl(267, 75%, 20%);
}

h2 {
  font-size: 2.25em;
}

.game-container {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
  padding: 1em 0.75em;
}

.space {
  width: 100%;
  height: 1px;
  flex: 1 0 100%;
}

.wrapper {
  padding: 1em 1.5em;
  max-width: 900px;
  margin: 0 auto;
}

main.wrapper {
  margin-top: 2.5em;
}

footer.wrapper {
  border-top: 2px solid currentcolor;
  margin-top: 4em;
}

.container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1em 0.5em;
}

input[type="text"] {
  display: block;
  width: 2em;
  height: 2em;
  font: inherit;
  color: inherit;
  text-transform: uppercase;
  text-align: center;
  border: 0;
  border-radius: 5px;
  outline: 2px solid currentcolor;

  &:focus {
    outline-style: dashed;
  }

  &:valid {
    outline-color: #43A047;
  }

  &:invalid ~ label {
    visibility: hidden;
  }
}

.levels > .movie:first-child {
  padding: 1em;
}

.movie, .congrats {
  display: grid;
  height: 100%;
  align-items: center;
  align-content: center;
  gap: 2em;
}

.congrats {
  font-size: 1.25em;
}

label {
  display: inline-block;
  border: 2px solid currentcolor;
  border-radius: 10px;
  cursor: pointer;
  background-color: #ffcc80;
  padding: 0.5em 1.5em;
  cursor: pointer;
}

input[type="radio"] {
  display: none;
}

@for $i from 0 through $number-of-movies {
  [id="movie-#{$i}"]:not(:checked) + .movie-#{$i} > .container > .letter,
  [id="movie-#{$i}"]:not(:checked) + .movie-#{$i} > .container > label,
  [id="movie-#{$i}"]:not(:checked) + .movie-#{$i} > .container > .space,
  [id="movie-#{$i}"]:not(:checked) + .movie-#{$i} > h2 {
    display: none;
  }

  [id="movie-#{$i}"]:not(:checked) + .movie-#{$i},
  [id="movie-#{$i}"]:not(:checked) + .movie-#{$i} > .container {
    gap: 0;
  }
}

[id="movie-#{$number-of-movies}"]:not(:checked) + .congrats {
  display: none;
}

              
            
!

JS

              
                /* if you want to see the answers, scroll down here */












/* 
   1. Harry Potter
        2. Star Wars
        3. Night at the museum
        4. Curious Case of Benjamin Button
        5. The princess and the frog
        6. Ratatouille
        7. Kung Fu Panda
        8. The Devil Wears Prada
        9. 27 Dresses
        10. Edward Scissor Hands
        11. Puss in Boots
        12. silence of the Lambs
        13. Twilight
   */

              
            
!
999px

Console