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.
<div class="site-canvas">
<div class="intro">
<div class="confetti"></div>
<div class="title">
<h1>JS Confetti</h1>
<h2>Web version of the awesome <a href="http://www.sketchconfetti.com/" target="_blank">Confetti</a> plugin for sketch.</h2>
<div class="button">Generate</div>
<div class="button">Settings</div>
<div class="button">Save PNG</div>
</div>
</div>
</div>
<div class="settings">
<h3>Configure your confetti <span class="close"></span></h3>
<div class="field half">
<label for="rows">Rows</label>
<input type="number" name="rows" value="5" />
</div>
<div class="field half">
<label for="rows">Columns</label>
<input type="number" name="columns" value="5" />
</div>
<div class="field full">
<input type="checkbox" name="opacity" checked="true" value="true" />
<label for="randomOpacity">Random Opacity</label>
</div>
<div class="field full">
<input type="checkbox" name="size" checked="true" value="true" />
<label for="randomSize">Random Size</label>
</div>
<div class="field full">
<input type="checkbox" name="rotation" checked="true" value="true" /><label for="randomRotation">Random Rotation</label>
</div>
</div>
<footer>
Made with <i class="fa fa-heart"></i>
<span>Want to buy me a beer? 3DuWe7JNHcJXDJknGWEewLrC712menPQka</span>
</footer>
body {
font-family:'Source Sans Pro';
overflow:hidden;
}
h1 {
font-family:'Montserrat';
font-size:6.2em;
text-shadow:0 2px 6px rgba(0,0,0,0.2);
}
h2 {
font-size:1.45em;
}
footer {
position:fixed;
left:10px;
right:10px;
bottom:10px;
color:rgba(255,255,255,0.6);
}
footer:hover {
color:#fff;
}
footer span {
float:right;
}
.site-canvas {
position:relative;
text-align:center;
}
.intro {
position:relative;
top:0;
left:0;
width:100%;
height:100vh;
color:#fff;
overflow:hidden;
}
.title {
position:absolute;
margin:auto;
top:0;
left:0;
right:0;
bottom:0;
width:100%;
height:190px;
}
.title a {
color:#fff;
border-bottom:1px solid #fff;
text-decoration:none;
}
.button {
margin:50px 10px 0;
width:160px;
height:50px;
line-height:50px;
background:#fff;
color:#8C1A6A;
font-size:1.2em;
font-weight:700;
border-radius:25px;
text-align:center;
box-shadow:0 10px 20px -5px rgba(0,0,0,0.2);
transition:0.05s ease-in-out;
display:inline-block;
user-select:none;
cursor:pointer;
}
.button:hover {
transform:scale(0.95);
}
.confetti {
position:fixed;
margin:auto;
top:0;
left:0;
width:100%;
height:100%;
background:linear-gradient(36deg, #8C1A6A, #FF0054);
}
.confetti-cell {
position:absolute;
top:0;
left:0;
width:20%;
height:20%;
opacity:0;
animation:350ms fadeIn cubic-bezier(0.22, 0.61, 0.36, 1);
animation-fill-mode:forwards;
}
.icon {
position:absolute;
top:0;
left:0;
background-position:50% 50%;
background-repeat:no-repeat;
background-size:contain;
width:50px;
height:50px;
display:block;
filter:invert(1);
}
.icon.i1 {
background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_cloud.svg);
}
.icon.i2 {
background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_headphones.svg);
}
.icon.i3 {
background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_heart.svg);
}
.icon.i4 {
background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_like.svg);
}
.icon.i5 {
background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_sun-cloud.svg);
}
.settings {
position:fixed;
margin:auto;
top:0;
left:0;
right:0;
bottom:0;
width:550px;
height:330px;
border-radius:15px;
background:#fff;
overflow:hidden;
opacity:0;
transform:scale(0.8) translate3d(0,-80px,0);
display:none;
animation:350ms fadeIn cubic-bezier(0.22, 0.61, 0.36, 1);
animation-fill-mode:forwards;
}
@keyframes fadeIn {
100%{
opacity:1;
transform:scale(1) translate3d(0,0,0);
}
}
.settings h3 {
margin:0 0 20px;
padding:20px;
font-size:1.6em;
font-weight:700;
color:#8C1A6A;
background:rgba(0,0,0,0.05);
}
.settings h3 span {
position:relative;
width:30px;
height:30px;
float:right;
display:block;
cursor:pointer;
}
.settings h3 span:before,
.settings h3 span:after {
position:absolute;
margin:auto;
top:0;
left:0;
right:0;
bottom:0;
width:30px;
height:2px;
background:#8C1A6A;
transform:rotate(45deg);
content:'';
}
.settings h3 span:after {
transform:rotate(-45deg);
}
.settings .field.half {
margin:0 20px 20px;
float:left;
}
.settings .field label {
margin-bottom:10px;
font-size:1.4em;
}
.settings .field.half input {
width:235px;
height:40px;
padding:10px;
font-size:18px;
border-radius:4px;
border:1px solid #e1e1e1;
box-sizing:border-box;
}
.settings .field.half input:focus {
outline:0 solid transparent;
border-color:#8C1A6A;
}
.settings .field.half label {
display:block;
}
.settings .field {
margin:20px;
}
.settings .field.full label {
margin-left:10px;
display:inline-block;
}
input[type=checkbox] {
width:20px;
height:20px;
display:inline-block;
}
(function(){
var confetti = {
rows: 6,
columns: 6,
randomOpacity: true, // 70% - 100%
randomSize: true,
randomRotation: true,
iconURLs: [
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_cloud.svg',
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_headphones.svg',
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_heart.svg',
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_like.svg',
'https://s3-us-west-2.amazonaws.com/s.cdpn.io/363972/nc-test-outline-64px_sun-cloud.svg'
]
};
settings();
$('.button').click(function(){
var id = $(this).text();
if(id == 'Generate'){
settings();
}else if(id == 'Save PNG'){
var node = document.querySelector('.icon');
domtoimage.toPng(node).then(function (dataUrl) {
download(dataUrl, 'confetti');
}).catch(function (error) {
console.error('oops, something went wrong!', error);
});
}else if(id == 'Settings'){
$('.settings').toggle();
}
});
$('.close').click(function(){
$('.settings').toggle();
});
$('input').on('change input', settings);
function settings() {
confetti.rows = $('input[name="rows"]').val();
confetti.columns = $('input[name="columns"]').val();
confetti.randomOpacity = $('input[name="opacity"]').prop('checked'); // 70% - 100%
confetti.randomSize = $('input[name="size"]').prop('checked');
confetti.randomRotation = $('input[name="rotation"]').prop('checked');
generateConfetti();
}
function generateConfetti() {
$('.confetti').html('<style>.confetti-cell{width:' + (100 / confetti.columns) + '%;height:' + (100 / confetti.rows) + '%;}</style>');
for(var i = 0;i < confetti.rows; i++) {
var top = (100 / confetti.rows) * i;
for(var q = 0;q < confetti.columns; q++) {
var icon = Math.floor(Math.random() * confetti.iconURLs.length) + 1;
var y = random100();
var x = random100();
var left = (100 / confetti.columns) * q;
$('.confetti').append('<div class="confetti-cell" style="top:' + top + '%;left:' + left +'%;animation-delay:' + (q * 100) + 'ms;"><i class="icon i'+ icon +'" style="top:'+y+'%;left:'+x+'%;opacity:' + opacity() + ';transform:rotate(' + rotate() + 'deg) scale(' + size() + ');"></i></div>');
}
}
}
function opacity() {
var state = 1;
if(confetti.randomOpacity) {
state = Math.random() + 0.5;
}
return state;
}
function rotate() {
var state = 0;
if(confetti.randomRotation) {
state = Math.floor(Math.random() * 70);
}
return state;
}
function size() {
var state = 1;
if(confetti.randomSize) {
state = 1 + (Math.random() - 0.6);
}
return state;
}
function random100() {
return Math.floor(Math.random() * 100);
}
function openInNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
})();
Also see: Tab Triggers