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.
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
@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;
}
/* 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
*/
Also see: Tab Triggers