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.
<h1>Grillade : KNACSS v6 grid system</h1>
<p class="txtcenter"><i>Should</i> work on IE10, IE11, Edge, Chrome, Firefox, Safari 8+, Android 4.4+. See <a href="http://grillade.knacss.com">grillade.knacss.com</a> (french)</p>
<p class="txtcenter"><b>Note:</b> on tiny screens (smartphones), all grids should be displayed within 1 unique column.</p>
<h2>the .grid object</h2>
<p><code>.grid</code> is meant for <b>one line display</b>. <br>Add any number of children and they will all be automagically inlined and have same size</p>
<section class="grid">
<div>just a div, no class</div>
<div>yay, me too</div>
<aside>hi there, I'm a <aside>!</aside>
</section>
<h2>adding gutters: .grid.has-gutter</h2>
<p>add a <code>.has-gutter</code> class when you need gutter between children</p>
<section class="grid has-gutter">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
</section>
<h2>sizing gutters</h2>
<p>add a <code>.has-gutter-l</code> or <code>.has-gutter-xl</code> class to change gutter size</p>
<section class="grid has-gutter-xl">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
</section>
<h2>.grid and children sizing</h2>
<p>children can be individually sized with classes such as <code>.one-half</code>, <code>.one-third</code>, <code>.one-quarter</code>, <code>.one-fifth</code>, <code>.two-thirds</code>, <code>.three-quarters</code>, <code>.one-sixth</code>, <code>.five-sixths</code>, or <code>.full</code></p>
<section class="grid">
<div class="one-fifth">.one-fifth</div>
<div>Lorem Elsass ipsum</div>
</section>
<h2>.grid.has-gutter and children sizing</h2>
<p>works also with <code>.has-gutter</code> class</p>
<section class="grid has-gutter">
<div class="one-fifth">.one-fifth</div>
<div>Lorem Elsass ipsum</div>
<div class="one-fifth">.one-fifth</div>
</section>
<h2>.grid-3</h2>
<p>add a number suffix to <code>.grid</code> such as <code>-3</code> to switch into <b>multi-lines display</b> (from 1 to 12)</p>
<section class="grid-3">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
</section>
<h2>.grid-3.has-gutter</h2>
<p>works also with <code>.has-gutter</code> class</p>
<section class="grid-3 has-gutter">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
</section>
<h2>.grid-3</h2>
<p>works also with sized children</p>
<section class="grid-3">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div class="one-half">.one-half</div>
<div class="one-half">.one-half</div>
<div class="one-third">.one-third</div>
<div class="two-thirds">.two-thirds</div>
<div class="full">.full</div>
<div class="one-quarter">.one-quarter</div>
<div class="one-quarter">.one-quarter</div>
<div class="one-half">.one-half</div>
</section>
<h2>push / pull element</h2>
<p>add <code>.push</code> or <code>.pull</code> class to create offsets</p>
<section class="grid-4">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div class="push">.push</div>
<div>Lorem Elsass</div>
</section>
<h2>first / last element</h2>
<p>add <code>.grid-item-first</code> or <code>.grid-item-last</code> class to reorder elements</p>
<section class="grid-4">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div class="grid-item-first">.grid-item-first</div>
<div>Lorem Elsass</div>
</section>
<h2>reverse order: </h2>
<p>add <code>--reverse</code> suffix on grid container to reverse the whole grid</p>
<section class="grid-3--reverse-small-2">
<div>one</div>
<div>two</div>
<div>three</div>
<div>four</div>
<div>five</div>
<div>six</div>
<div>seven</div>
</section>
<h2>.grid-3-small-2</h2>
<p>add <code>-small-X</code> (X from 1 to 4) suffix to define column numbers on small screens, here will be 2 columns. <i>Note : on tiny screens, value is always 1 column</i></p>
<section class="grid-3-small-2">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div class="one-half">.one-half</div>
<div class="one-half">.one-half</div>
<div class="one-third">.one-third</div>
<div class="two-thirds">.two-thirds</div>
<div class="full">.full</div>
<div class="one-quarter">.one-quarter</div>
<div class="one-quarter">.one-quarter</div>
<div class="one-half">.one-half</div>
</section>
<h2>.grid-4-small-3</h2>
<section class="grid-4-small-3">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
</section>
<h2>.grid-6-small-4</h2>
<section class="grid-6-small-4">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
</section>
<h2>.grid-3-small-2.has-gutter</h2>
<p>works also with <code>.has-gutter</code> class</p>
<section class="grid-3-small-2 has-gutter">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div class="one-half">.one-half</div>
<div class="one-half">.one-half</div>
<div class="one-third">.one-third</div>
<div class="two-thirds">.two-thirds</div>
<div class="full">.full</div>
<div class="one-quarter">.one-quarter</div>
<div class="one-quarter">.one-quarter</div>
<div class="one-half">.one-half</div>
</section>
<h2>Sass mixin</h2>
<p>you can design your own Sass mixin. Here : <code>.grid-sans-gouttiere { @include grid(4, 0); }</code></p>
<section class="grid-sans-gouttiere">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
</section>
<h2>Sass mixin and gutter</h2>
<p>works also. Here : <code>.grid-perso { @include grid(4, 2rem); }</code></p>
<section class="grid-perso">
<div>Lorem Elsass ipsum Choucroute knack</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass ipsum Choucroute</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
<div>Lorem Elsass</div>
</section>
// Responsive breakpoints variables
// Warning : you should use your own values,
// regardless of the devices
// Best practise : (max-width: $BP) and (min-width: ($BP + 1))
$tiny: 543px !default; // or 'em' if you prefer, of course
$small: 767px !default;
$medium: 991px !default;
$large: 1199px !default;
$extra-large: 1439px !default;
// gutter values for grid layouts. Unit can be: %, px, em, rem
$grid-gutters: (
'': 1rem,
'-l': 2rem,
'-xl': 4rem
);
// IEfixing, see
// https://github.com/alsacreations/KNACSS/issues/133;
$iefix: .01px;
@media (min-width: ($tiny + 1)) {
[class*=" grid-"],
[class^="grid-"] {
display: flex;
flex-direction: row;
flex-wrap: wrap;
& > * {
box-sizing: border-box;
min-width: 0;
min-height: 0;
}
}
}
// Multi-line grid constructor
// example : .grid-perso { @include grid(12, 3rem); }
@mixin grid($grid-number:1, $own-gutter:0) {
& > * {
width: calc(100% / #{$grid-number} - #{$iefix});
}
@each $affix, $size in $grid-gutters {
&.has-gutter#{$affix} {
margin-right: -$size / 2;
margin-left: -$size / 2;
& > * {
width: calc(100% / #{$grid-number} - #{$size} - #{$iefix});
margin-right: $size / 2;
margin-left: $size / 2;
}
}
}
@if ($own-gutter != 0) {
margin-right: -$own-gutter / 2;
margin-left: -$own-gutter / 2;
& > * {
width: calc(100% / #{$grid-number} - #{$own-gutter} - #{$iefix});
margin-right: $own-gutter / 2;
margin-left: $own-gutter / 2;
}
}
}
// Mono-line grid constructor (.grid)
@media (min-width: ($tiny + 1)) {
.grid {
display: flex;
& > * {
flex: 1 1 0%;
box-sizing: border-box;
min-width: 0;
min-height: 0;
}
@each $affix, $size in $grid-gutters {
&.has-gutter#{$affix} > * + * {
margin-left: calc(#{$size} - #{$iefix});
}
}
}
}
// Constructing grids : will be compiled in CSS
@media (min-width: ($tiny + 1)) {
@for $i from 2 through 12{
[class*="grid-#{$i}"] {
@include grid(#{$i},0);
}
}
}
// Grid offsets
.push {
margin-left: auto !important;
}
.pull {
margin-right: auto !important;
}
/* Grid order */
.grid-item-first {
order: -1;
}
.grid-item-last {
order: 1;
}
[class*="--reverse"] {
flex-direction: row-reverse;
}
// sizing individual children
@media (min-width: ($tiny + 1)) {
@each $flow, $divider in ("full" "1"),
("one-half" "2"),
("one-third" "3"),
("one-quarter" "4"),
("one-fifth" "5"),
("one-sixth" "6"),
("two-thirds" "3 * 2"),
("three-quarters" "4 * 3"),
("five-sixths" "6 * 5")
{
.#{$flow} {
flex: 0 0 auto;
width: calc(100% / #{$divider} - #{$iefix});
}
@each $affix, $size in $grid-gutters {
.has-gutter#{$affix} .#{$flow} {
width: calc(100% / #{$divider} - #{$size} - #{$iefix});
}
}
}
}
/* Responsive Small Breakpoint */
// -small-X suffix means "X columns on small screen"
// example : .grid-4-small-2 will be 1 column (tiny and down) then 2 columns (until small) then 4 columns
@media (min-width: ($tiny + 1)) and (max-width: $small) {
@for $i from 1 through 4 {
[class*="-small-#{$i}"] {
& > * {
width: calc(100% / #{$i} - #{$iefix});
}
@each $affix, $size in $grid-gutters {
&.has-gutter#{$affix} > * {
width: calc(100% / #{$i} - #{$size} - #{$iefix});
}
}
}
}
}
.grid-sans-gouttiere {
@media (min-width: $tiny + 1) {
@include grid(3, 0);
}
}
.grid-perso {
@media (min-width: $tiny + 1) {
@include grid(4, 2rem);
}
}
/* deco */
html {
font-size: 62.5%;
}
body {
margin: 2rem;
padding: 1rem 0;
font-family: arial, sans;
font-size: 1.6em;
}
[class*="grid"] > * {
padding: .5em;
background: olivedrab;
margin-bottom: 1rem;
color: #fff;
outline: 1px dotted #fff;
}
h1 {
margin: 0 0 1em;
color: #345;
text-align: center;
font-family: georgia, "trebuchet ms", arial, serif;
}
h2 {
display: inline-block;
margin: 3rem 0 .6rem;
color: #567;
font-family: georgia, "trebuchet ms", arial, serif;
}
p {margin-top: 0;}
.txtcenter {
text-align: center;
}
code {
font-size: 130%;
color: firebrick;
}
Also see: Tab Triggers