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.
<div class="panel">
<h1>Memory!</h1>
<div class="counter">0</div>
<button id="reset"><svg xmlns="http://www.w3.org/2000/svg" width="124" height="111" viewBox="1651 -13 124 111">
<path fill="#FFF" fill-rule="evenodd" d="M1761.8 44c-.4 13.6-5.7 27-16 37.4-21.6 21.5-56.4 21.6-77.8 0-21.4-21.3-21.3-56 0-77.5C1679-7 1693-12.3 1707-12.4V8.5c-8.8 0-17.6 3.5-24.3 10.2-13.7 13.7-13.7 35.8 0 49.5 13.5 13.6 35.7 13.6 49.3 0 6.7-6.8 10-15.5 10.3-24.2h-13.4l23-30 23 30h-12.8z"/>
</svg>
</button>
</div>
<div class="container">
<div class="card yellow">
<div class="front">
</div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="60 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(60 140)">
<circle cx="100" cy="100" r="100" fill="#FFD400"/>
<path fill="#FFF" d="M100 180c44 0 80-36 80-80 0-44.3-36-80-80-80-44.3 0-80 35.7-80 80 0 44 35.7 80 80 80zm-.2-52.2L67 145l6.2-36.5-26.6-26 36.8-5.3L99.8 44 116.3 77l36.8 5.4-26.5 26 6.2 36.5-33-17.2z" opacity=".8"/>
</g>
</svg>
</div>
</div>
<div class="card black">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="321 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(321 140)">
<circle cx="100" cy="100" r="100" fill="#000"/>
<path fill="#FFF" fill-opacity=".5" d="M113 100V45H87v55H60v26h27v29h26v-29h27v-26h-27zm-13 80c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/>
</g>
</svg>
</div>
</div>
<div class="card greenblue">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="582 453 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(582 453)">
<circle cx="100" cy="100" r="100" fill="#006860"/>
<path fill="#FFF" fill-opacity=".5" d="M100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zM69.6 37l5 26.8c.4 2.7 1 2.7 1.5 0L80.4 35l4.5 28.8c.4 2.7 1.2 2.7 1.7 0l5-26.8L94 69.6c.3 2.8-1 6.6-3 8.5l-2.6 2.7c-2 2-3.5 5.7-3.4 8.5 0 0 2.8 75.3-4 75.2-6.8 0-5-75.2-5-75.2 0-2.7-1.4-6.6-3.4-8.5L70 78c-2-1.8-3.3-5.7-3-8.4L69.5 37zm56 0S111 55.5 111 78.7c0 23 5.3 24 5.3 24L115 159c0 2.8 2 5 4.8 5h1c2.7 0 5-2.2 4.8-5l-1.4-56.2 1.5-65.8z"/>
</g>
</svg>
</div>
</div>
<div class="card brown">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="582 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(582 140)">
<circle cx="100" cy="100" r="100" fill="#683900"/>
<path fill="#FFF" fill-opacity=".5" d="M126.8 81h14c3 0 5.2 2.2 5.2 5v28c0 2.8-2.3 5-5 5h-14.3v-9.5h4.5c3 0 5.2-2.2 5.2-5v-9c0-2.8-2.3-5-5.2-5h-4.4V81zM100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zM69 65h57.8v70H69V65z"/>
</g>
</svg>
</div>
</div>
<div class="card greenblue">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="582 453 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(582 453)">
<circle cx="100" cy="100" r="100" fill="#006860"/>
<path fill="#FFF" fill-opacity=".5" d="M100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zM69.6 37l5 26.8c.4 2.7 1 2.7 1.5 0L80.4 35l4.5 28.8c.4 2.7 1.2 2.7 1.7 0l5-26.8L94 69.6c.3 2.8-1 6.6-3 8.5l-2.6 2.7c-2 2-3.5 5.7-3.4 8.5 0 0 2.8 75.3-4 75.2-6.8 0-5-75.2-5-75.2 0-2.7-1.4-6.6-3.4-8.5L70 78c-2-1.8-3.3-5.7-3-8.4L69.5 37zm56 0S111 55.5 111 78.7c0 23 5.3 24 5.3 24L115 159c0 2.8 2 5 4.8 5h1c2.7 0 5-2.2 4.8-5l-1.4-56.2 1.5-65.8z"/>
</g>
</svg>
</div>
</div>
<div class="card red">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="843 453 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(843 453)">
<circle cx="100" cy="100" r="100" fill="#C40E01"/>
<path fill="#FFF" fill-opacity=".5" d="M100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zm0-29.2l-40.5-40.4c-11.2-11-11.2-29.2 0-40.3 11-11 29.2-11 40.3 0 0 0 .8-.2 1-.5 11.2-11 29.3-11 40.4 0 11.2 11.2 11.2 29.2 0 40.4L100 150.7z"/>
</g>
</svg>
</div>
</div>
<div class="card green">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="843 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(843 140)">
<circle cx="100" cy="100" r="100" fill="#086800"/>
<path fill="#FFF" fill-opacity=".5" d="M100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zm-56-75.4c0-4.4 3.6-8 8-8h11.5c4.5 0 8 3.6 8 8V128c0 4.4-3.5 8-8 8H52c-4.4 0-8-3.6-8-8v-23.4zm84.3 0c0-4.4 3.6-8 8-8h11.5c4.4 0 8 3.6 8 8V128c0 4.4-3.5 8-8 8h-11.5c-4.4 0-8-3.6-8-8v-23.4zm20.2-8c0-26.8-21.8-48.6-48.6-48.6-27 0-48.7 21.8-48.7 48.6h12C63.5 76.3 80 60 100.3 60c20.4 0 37 16.3 37.2 36.6h11z"/>
</g>
</svg>
</div>
</div>
<div class="card black">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="321 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(321 140)">
<circle cx="100" cy="100" r="100" fill="#000"/>
<path fill="#FFF" fill-opacity=".5" d="M113 100V45H87v55H60v26h27v29h26v-29h27v-26h-27zm-13 80c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/>
</g>
</svg>
</div>
</div>
<div class="card blue">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="1889 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(1889 140)">
<circle cx="100" cy="100" r="100" fill="#4C6FB0"/>
<path fill="#FFF" fill-opacity=".5" d="M95 90v5c-.6 16.5-14.5 29.5-31 29-16.6-.7-29.6-14.6-29-31 .6-16.7 20-17.5 36.6-17 12.4.6 19.7 1.6 22.3 9 1.5-.7 3.6-1 5.8-1 2.2 0 4.2.3 6 1 2.5-7.4 9.8-8.4 22.2-9 16.5-.5 36 .3 36.6 17 .5 16.4-12.4 30.3-29 31-16.5.5-30.4-12.5-31-29v-5c-1.3-.6-3-1-4.8-1-1.8 0-3.5.4-5 1zm5 90c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/>
</g>
</svg>
</div>
</div>
<div class="card orange">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="1365 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(1365 140)">
<circle cx="100" cy="100" r="100" fill="#F49D37"/>
<path fill="#FFF" fill-opacity=".5" d="M130.7 96.2c1.4 12-4.2 24-15.2 30.4-11 6.3-24.3 5.2-34-2-20.8 9.7-37 13.7-39.6 9-2.8-4.6 8.6-16.5 27.4-29.8-1.6-12 4-24.3 15-30.7 11.3-6.4 25-5 34.5 2.4 20.2-9.2 35.6-13 38.3-8.4 2.6 4.6-8.4 16.2-26.6 29.2zM100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/>
<path fill="#FFF" fill-opacity=".5" d="M74.8 117.8c-4.2 1-7 1-7.7-.2-.6-1.3.8-3.7 4-6.8.6 1.5 1.4 3 2.2 4.5l1.6 2.5zM125 81.8c4.2-1 7-1 7.7.2.7 1.2-.8 3.7-4 6.8-.5-1.5-1.3-3-2-4.5l-1.7-2.5z"/>
</g>
</svg>
</div>
</div>
<div class="card red">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="843 453 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(843 453)">
<circle cx="100" cy="100" r="100" fill="#C40E01"/>
<path fill="#FFF" fill-opacity=".5" d="M100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zm0-29.2l-40.5-40.4c-11.2-11-11.2-29.2 0-40.3 11-11 29.2-11 40.3 0 0 0 .8-.2 1-.5 11.2-11 29.3-11 40.4 0 11.2 11.2 11.2 29.2 0 40.4L100 150.7z"/>
</g>
</svg>
</div>
</div>
<div class="card brown">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="582 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(582 140)">
<circle cx="100" cy="100" r="100" fill="#683900"/>
<path fill="#FFF" fill-opacity=".5" d="M126.8 81h14c3 0 5.2 2.2 5.2 5v28c0 2.8-2.3 5-5 5h-14.3v-9.5h4.5c3 0 5.2-2.2 5.2-5v-9c0-2.8-2.3-5-5.2-5h-4.4V81zM100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zM69 65h57.8v70H69V65z"/>
</g>
</svg>
</div>
</div>
<div class="card blue">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="1889 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(1889 140)">
<circle cx="100" cy="100" r="100" fill="#4C6FB0"/>
<path fill="#FFF" fill-opacity=".5" d="M95 90v5c-.6 16.5-14.5 29.5-31 29-16.6-.7-29.6-14.6-29-31 .6-16.7 20-17.5 36.6-17 12.4.6 19.7 1.6 22.3 9 1.5-.7 3.6-1 5.8-1 2.2 0 4.2.3 6 1 2.5-7.4 9.8-8.4 22.2-9 16.5-.5 36 .3 36.6 17 .5 16.4-12.4 30.3-29 31-16.5.5-30.4-12.5-31-29v-5c-1.3-.6-3-1-4.8-1-1.8 0-3.5.4-5 1zm5 90c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/>
</g>
</svg>
</div>
</div>
<div class="card green">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="843 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(843 140)">
<circle cx="100" cy="100" r="100" fill="#086800"/>
<path fill="#FFF" fill-opacity=".5" d="M100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80zm-56-75.4c0-4.4 3.6-8 8-8h11.5c4.5 0 8 3.6 8 8V128c0 4.4-3.5 8-8 8H52c-4.4 0-8-3.6-8-8v-23.4zm84.3 0c0-4.4 3.6-8 8-8h11.5c4.4 0 8 3.6 8 8V128c0 4.4-3.5 8-8 8h-11.5c-4.4 0-8-3.6-8-8v-23.4zm20.2-8c0-26.8-21.8-48.6-48.6-48.6-27 0-48.7 21.8-48.7 48.6h12C63.5 76.3 80 60 100.3 60c20.4 0 37 16.3 37.2 36.6h11z"/>
</g>
</svg>
</div>
</div>
<div class="card orange">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="1365 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(1365 140)">
<circle cx="100" cy="100" r="100" fill="#F49D37"/>
<path fill="#FFF" fill-opacity=".5" d="M130.7 96.2c1.4 12-4.2 24-15.2 30.4-11 6.3-24.3 5.2-34-2-20.8 9.7-37 13.7-39.6 9-2.8-4.6 8.6-16.5 27.4-29.8-1.6-12 4-24.3 15-30.7 11.3-6.4 25-5 34.5 2.4 20.2-9.2 35.6-13 38.3-8.4 2.6 4.6-8.4 16.2-26.6 29.2zM100 180c44.2 0 80-35.8 80-80s-35.8-80-80-80-80 35.8-80 80 35.8 80 80 80z"/>
<path fill="#FFF" fill-opacity=".5" d="M74.8 117.8c-4.2 1-7 1-7.7-.2-.6-1.3.8-3.7 4-6.8.6 1.5 1.4 3 2.2 4.5l1.6 2.5zM125 81.8c4.2-1 7-1 7.7.2.7 1.2-.8 3.7-4 6.8-.5-1.5-1.3-3-2-4.5l-1.7-2.5z"/>
</g>
</svg>
</div>
</div>
<div class="card yellow">
<div class="front"></div>
<div class="back">
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="60 140 200 200">
<g fill="none" fill-rule="evenodd" transform="translate(60 140)">
<circle cx="100" cy="100" r="100" fill="#FFD400"/>
<path fill="#FFF" d="M100 180c44 0 80-36 80-80 0-44.3-36-80-80-80-44.3 0-80 35.7-80 80 0 44 35.7 80 80 80zm-.2-52.2L67 145l6.2-36.5-26.6-26 36.8-5.3L99.8 44 116.3 77l36.8 5.4-26.5 26 6.2 36.5-33-17.2z" opacity=".8"/>
</g>
</svg>
</div>
</div>
</div>
$yellow: #FFD400;
$black: #000;
$brown: #683900;
$green: #086800;
$orange: #F49D37;
$blue: #4C6FB0;
$greenblue: #006860;
$red: #C40E01;
$front: #F5D5F4;
$semitransparent: rgba(255,255,255,0.75);
$grad1: #fff;
$grad2: transparent;
$stripes: linear-gradient(135deg,
$grad1 0%,
$grad1 24.9%,
$grad2 25%,
$grad2 49.9%,
$grad1 50%,
$grad1 74.9%,
$grad2 75%,
$grad2 100%);
$stripe-size: 5em;
@import url('https://fonts.googleapis.com/css?family=Bahiana');
.panel {
background: #fff;
font-family: "Bahiana", sans-serif;
font-size: 2rem;
display: flex;
h1 {
font-size: 4rem;
padding: 0;
margin: 0;
}
.counter, button {
font-size: 1em;
padding: .5em;
margin: auto 0 auto auto;
height: 2em;
width: 2em;
box-sizing: border-box;
}
.counter {
background: #eee;
text-align: center;
}
button {
background: #444;
color: #fff;
border: none;
margin-left: 0;
svg {
height: 100%;
width: 100%;
padding-left: .1em;
box-sizing: border-box;
}
}
}
.container svg {
width: 100%;
height: 100%;
box-sizing: border-box;
background-color: $semitransparent;
padding: 1em;
}
.container {
display: flex;
flex-flow: row wrap;
}
.card {
font-size: 10px;
@media(min-width: 600px) {
font-size: 16px;
}
margin: .75em;
border-radius: .35em;
box-shadow: 0 .05em .25em rgba(0,0,0,.15);
width: 10em;
height: 10em;
display: inline-block;
position: relative;
overflow: hidden;
transition: transform .2s linear;
.back {
opacity: 0;
transform: scaleX(-1);
}
.front {
opacity: 1;
background-color: $front;
}
&.flipped, &.clear {
transform: scaleX(-1);
.front {
opacity: 0;
}
.back {
opacity: 1;
}
&.yellow .back {
background-color: $yellow;
}
&.green .back {
background-color: $green;
}
&.brown .back {
background-color: $brown;
}
&.black .back {
background-color: $black;
}
&.orange .back {
background-color: $orange;
}
&.blue .back {
background-color: $blue;
}
&.greenblue .back {
background-color: $greenblue;
}
&.red .back {
background-color: $red;
}
}
div {
transition: opacity 0s linear .1s;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: $stripes;
background-size: $stripe-size $stripe-size;
}
}
var cards = [];
var counter = 0;
$(".card").click(function() {
var el = $(this);
if (!el.is(".flipped, .clear")) {
checkCards();
flipCard(el);
updateCounter();
}
});
$("#reset").click(function() {
$(".card").removeClass("flipped clear");
cards = [];
counter = 0;
updateCounter();
$(".card").randomize();
});
function updateCounter() {
if (cards.length == 2) {
counter++;
}
$(".counter").text(counter);
}
function flipCard(el) {
if (cards.length == 2) {
$(".flipped").removeClass("flipped");
cards = [];
}
cards.push(el.attr("class"));
el.addClass("flipped");
}
function checkCards() {
if (cards.length == 2) {
if (cards[0] == cards[1]) { // if correct
$(".flipped").addClass("clear").removeClass("flipped");
cards = [];
}
}
}
// randomize function found on stackoverflow:
// http://stackoverflow.com/a/11766418
$.fn.randomize = function(selector) {
(selector ? this.find(selector) : this).parent().each(function() {
$(this).children(selector).sort(function() {
return Math.random() - 0.5;
}).detach().appendTo(this);
});
return this;
};
Also see: Tab Triggers