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.
- let data = [
- {
- name: 'Gingerbread',
- date: '21st of July 2020',
- tags: ['ginger', 'cloves', 'nutmeg', 'cinnamon', 'honey'],
- text: 'Tiramisu biscuit liquorice dragée tootsie roll. Marzipan soufflé donut bonbon powder. Sugar plum chocolate bar donut cake marzipan biscuit liquorice liquorice. Muffin brownie chocolate cake biscuit. Soufflé cookie pastry jelly beans pudding. Oat cake cupcake cheesecake tootsie roll. Croissant wafer caramels. Lollipop macaroon gingerbread pudding.'
- },
- {
- name: 'Macaron',
- date: '4th of June 2020',
- tags: ['egg whites', 'sugar', 'almond', 'cream'],
- text: 'Tart jelly. Marshmallow brownie icing tart. Sugar plum brownie sugar plum tootsie roll liquorice lemon drops croissant. Dragée pudding chocolate jelly-o brownie.'
- },
- {
- name: 'Lava cake',
- date: '23rd of May 2020',
- tags: ['chocolate', 'cake', 'gooey', 'moist'],
- text: 'Cheesecake marzipan chocolate bar lollipop. Sweet roll oat cake powder brownie chupa chups gingerbread wafer wafer. Tiramisu cheesecake fruitcake cake. Jelly beans dessert fruitcake carrot cake ice cream.'
- },
- {
- name: 'Salted caramel truffles',
- date: '2nd of May 2020',
- tags: ['salted caramel', 'truffle'],
- text: 'Fruitcake jelly chocolate cake croissant donut pastry cookie jelly beans gingerbread. Candy canes macaroon dragée jelly beans tootsie roll icing jelly fruitcake tiramisu. Lemon drops wafer jujubes. Tootsie roll caramels chocolate cake sugar plum cookie biscuit tootsie roll apple pie cake. Marzipan pudding cake. Carrot cake ice cream chocolate bar toffee apple pie toffee.'
- },
- {
- name: 'Lemon ice cream',
- date: '8th of April 2020',
- tags: ['ice cream', 'lemon', 'cooling'],
- text: 'Wafer lollipop sugar plum. Candy chupa chups sweet roll. Cookie dessert marshmallow apple pie brownie tiramisu cookie candy. Jujubes bonbon danish cotton candy bonbon croissant cheesecake jelly-o icing. Carrot cake marshmallow jelly candy. Carrot cake pie lollipop sweet roll sweet roll ice cream caramels cheesecake chupa chups. Sugar plum lemon drops tiramisu pie. Chocolate gummies jelly-o. Fruitcake halvah dessert marshmallow jelly-o cake.'
- },
- {
- name: 'Brownie',
- date: '20th of March 2020',
- tags: ['pecan', 'chocolate', 'caramel', 'moist'],
- text: 'Liquorice muffin dessert toffee tootsie roll tiramisu. Lollipop gummi bears bonbon. Gummies gummi bears brownie muffin gingerbread. Cheesecake chocolate bar brownie. Tiramisu wafer cotton candy bonbon. Soufflé wafer jelly dragée candy cake gummi bears gingerbread dessert. Gummies cupcake lollipop soufflé biscuit icing sweet. Tart cake chupa chups gingerbread cake. Powder bonbon lollipop lollipop marzipan fruitcake.'
- },
- {
- name: 'Apple pie',
- date: '17th of February 2020',
- tags: ['pie', 'apple', 'moist'],
- text: 'Lollipop cheesecake sugar plum macaroon fruitcake. Powder muffin jelly beans carrot cake sweet roll gingerbread powder. Brownie brownie carrot cake gummi bears cotton candy cookie candy topping topping.'
- }
- ]
body.grid--masonry
- data.forEach(o => {
article
header
h3 #{o.name}
time.breakout #{o.date}
div.tags
- o.tags.forEach(t => {
a.tag(href='#') #{t}
- })
section #{o.text}
footer.breakout
a.more(href='#') more
- });
p Demo created for my CSS-Tricks article <a href="https://css-tricks.com/a-lightweight-masonry-solution/" target="_blank">A Lightweight Masonry Solution</a> - make sure you check it out!<br>All demos created for this article can be found in <a href="https://codepen.io/collection/DYRJxR" target="_blank">this collection</a>.
$w: minmax(Min(20em, 100%), 1fr);
$s: .5em;
/* basic reset */
* {
box-sizing: inherit;
margin: 0
}
/* basic masonry styles - same as for the image grid */
.grid--masonry {
display: grid;
grid-template-columns: repeat(auto-fit, $w);
grid-template-rows: masonry;
justify-content: center;
grid-gap: $s;
padding: $s;
> * { align-self: start }
> :first-child { grid-column: 1/ -1 }
}
/* prettifying styles */
html {
box-sizing: border-box;
background:
linear-gradient(to left top, #555, #959595) fixed;
color: #ddd;
font: 1em/ 1.375 exo, trebuchet ms, sans-serif
}
body {
margin: 0 auto;
padding: 0 2vmin;
max-width: 80em
}
article {
position: relative;
background: linear-gradient(to left top, #1c1c1c, #222)
}
header, section, footer { padding: 2vmin }
header { border-bottom: solid 1px #000 }
section { border-top: solid 1px #363636 }
footer { text-align: right }
time { font-size: .875em }
a {
display: inline-block;
color: #fadd6a;
text-decoration: none
}
.tag {
display: inline-block;
margin-right: 2vmin;
font-size: .875em;
&::before {
margin-right: .25em;
content: '🏷️'
}
}
let grids = [...document.querySelectorAll('.grid--masonry')];
if(grids.length && getComputedStyle(grids[0]).gridTemplateRows !== 'masonry') {
grids = grids.map(grid => ({
_el: grid,
gap: parseFloat(getComputedStyle(grid).gridRowGap),
items: [...grid.childNodes].filter(c => c.nodeType === 1 && +getComputedStyle(c).gridColumnEnd !== -1),
ncol: 0,
mod: 0
}));
function layout() {
grids.forEach(grid => {
/* get the post relayout number of columns */
let ncol = getComputedStyle(grid._el).gridTemplateColumns.split(' ').length;
grid.items.forEach(c => {
let new_h = c.getBoundingClientRect().height;
if(new_h !== +c.dataset.h) {
c.dataset.h = new_h;
grid.mod++
}
});
/* if the number of columns has changed */
if(grid.ncol !== ncol || grid.mod) {
/* update number of columns */
grid.ncol = ncol;
/* revert to initial positioning, no margin */
grid.items.forEach(c => c.style.removeProperty('margin-top'));
/* if we have more than one column */
if(grid.ncol > 1) {
grid.items.slice(ncol).forEach((c, i) => {
let prev_fin = grid.items[i].getBoundingClientRect().bottom /* bottom edge of item above */,
curr_ini = c.getBoundingClientRect().top /* top edge of current item */;
c.style.marginTop = `${prev_fin + grid.gap - curr_ini}px`
})
}
grid.mod = 0
}
})
}
addEventListener('load', e => {
layout(); /* initial load */
addEventListener('resize', layout, false) /* on resize */
}, false);
}
Also see: Tab Triggers