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="grid">
<div class="cell cell-1">Area 51 👽</div>
<div class="cell cell-2">2<br><br><br><br></div>
<div class="cell cell-3">3</div>
<div class="cell cell-4">4</div>
<div class="cell cell-5">5</div>
<div class="cell cell-6">6</div>
<div class="cell cell-7">7</div>
<div class="cell cell-8">8</div>
<div class="cell cell-9">9</div>
<div class="cell cell-10">10</div>
<div class="cell cell-11">11</div>
<div class="cell cell-12">12</div>
<div class="cell cell-13">
<div class="cell cell-13a">13a</div>
<div class="cell cell-13b">13b</div>
<div class="cell cell-13c">13c</div>
</div>
<pre class="cell cell-14">
<span>// grid map (cols, rows, gap, col-gap, row-gap)</span>
$grid: (
cols: repeat(5, 1fr) 2fr,
gap: 10px
);
<span>// create grid</span>
.grid {
@include grid($grid);
}
<span>// set column, row and spans</span>
.cell {
@include grid-column(1, 2); <span>// column, col-span</span>
@include grid-row(1, 2); <span>// row, row-span</span>
}
<span>// set column, row and spans in one include</span>
.cell {
@include grid-cell(1, 2, 1, 2); // column, col-span, row, row-span
}
<span>// set column, row and spans using area keys
// keys: (column, col-span, row, row-span)</span>
$grid-areas: (
area-51 : (1, 2, 1, 2),
studio-54: (3, 2, 1, 2)
);
.cell {
@include grid-area(area-51);
}
.cell {
@include grid-area(studio-54);
}
</pre>
</div>
// ==========================================================
// CSS Grid Mixins (take one)
// ==========================================================
// global grid variables (☠= don't touch)
$☠__ms-col-gap: null;
$☠__ms-row-gap: null;
$☠__ms-col-count: null;
$☠__ms-row-count: null;
//
// repeat function
//
@function repeat($repeat, $stuff: 1fr){
$list: ();
@for $i from 1 through $repeat { $list: append($list, $stuff, space); }
@return $list;
}
//
// grid-column mixin
//
@mixin grid-column($start: auto, $span: 1){
// grid-column-gap using left margin
@if $☠__ms-col-gap and not $☠__ms-col-count and $start != 1 {
margin-left: $☠__ms-col-gap;
@supports (grid-column-gap: 1px){ margin-left: 0; }
}
-ms-grid-column: if($☠__ms-col-count, $start + $start - 1, $start);
-ms-grid-column-span: if($☠__ms-col-count, $span + $span - 1, $span);
grid-column: #{$start}/#{$start + $span};
@content;
}
//
// grid-row mixin
//
@mixin grid-row($start: auto, $span: 1){
// grid-row-gap using top margin
@if $☠__ms-row-gap and not $☠__ms-row-count and $start != 1 {
margin-top: $☠__ms-row-gap;
@supports (grid-row-gap: 1px){ margin-top: 0; }
}
-ms-grid-row: if($☠__ms-row-count, $start + $start - 1, $start);
-ms-grid-row-span: if($☠__ms-row-count, $span + $span - 1, $span);
grid-row: #{$start}/#{$start + $span};
@content;
}
//
// grid-cell mixin
//
@mixin grid-cell($col-start: auto, $col-span: 1, $row-start: auto, $row-span: 1){
@include grid-column($col-start, $col-span);
@include grid-row($row-start, $row-span);
@content;
}
//
// grid-area mixin
//
@mixin grid-area($area){
$area: map-get($grid-areas, $area);
@include grid-column(nth($area, 1), nth($area, 2));
@include grid-row(nth($area, 3), nth($area, 4));
@content;
}
//
// grid mixin
//
@mixin grid($grid-map){
$cols: map-get($grid-map, cols);
$rows: map-get($grid-map, rows);
$gap: map-get($grid-map, gap);
$col-gap: map-get($grid-map, col-gap);
$col-gap: if($col-gap,$col-gap,$gap);
$row-gap: map-get($grid-map, row-gap);
$row-gap: if($row-gap,$row-gap,$gap);
// if cols or rows are numbers convert to fraction lists
@if $cols and length($cols) == 1 and unitless($cols) { $cols: repeat($cols); }
@if $rows and length($rows) == 1 and unitless($rows) { $rows: repeat($rows); }
// ie does not support grid gap - why we insert the gap space as a row or colum
// note! the first loop is to ensure cols/rows are not a multidimensional list
// (when generated by the repeat function)
$ms-cols: null;
$ms-rows: null;
@if $col-gap and $cols {
$ms-cols: ();
@each $col in $cols { $ms-cols: if( type-of($col) == list, join($ms-cols, $col), append($ms-cols, $col)); }
@for $i from 1 through length($ms-cols) - 1{ $ms-cols: set-nth($ms-cols, $i, nth($ms-cols,$i) $col-gap); }
// globalize ms col count (used by grid-column)
$☠__ms-col-count: length($ms-cols) !global;
}
@if $row-gap and $rows {
$ms-rows: ();
@each $row in $rows { $ms-rows: if( type-of($row) == list, join($ms-rows, $row), append($ms-rows, $row)); }
@for $i from 1 through length($ms-rows) - 1 { $ms-rows: set-nth($ms-rows, $i, nth($ms-rows,$i) $row-gap); }
// globalize ms row count (used by grid-row)
$☠__ms-row-count: length($ms-rows) !global;
}
//
$☠__ms-col-gap: $col-gap !global;
$☠__ms-row-gap: $row-gap !global;
display: -ms-grid;
display: grid;
-ms-grid-columns: $ms-cols or $cols;
-ms-grid-rows: $ms-rows or $rows;
grid-template-columns: $cols;
grid-template-rows: $rows;
grid-column-gap: $col-gap;
grid-row-gap: $row-gap;
@content;
}
// ==========================================================
// Use example
// ==========================================================
//
// grid map (cols, rows, gap, col-gap, row-gap)
//
$grid: (
cols: repeat(5, 1fr) 2fr,
row-gap: 8px,
col-gap: 16px
);
//
// Grid area map (col, col-span, row, row-span)
//
$grid-areas:(
area-51: (1, 2, 1, 2)
);
.grid {
// create grid
@include grid($grid);
max-width: 800px;
margin-left : auto;
margin-right: auto;
}
// just a bit of color and padding
.grid { background-color: whitesmoke; border:1px solid #ccc; }
.cell { background-color: #ccc; padding: 5px; }
.cell-1 {
// grid area
@include grid-area(area-51);
background-color: magenta;
color: white;
}
.cell-2 {
// grid cell (grid-column + grid-row)
@include grid-cell(3, 1, 2, 1);
background-color: rebeccapurple;
color: white;
}
.cell-3 {
@include grid-column(3, 1);
@include grid-row(1, 1);
}
.cell-4 {
@include grid-column(4, 1);
@include grid-row(1, 1);
}
.cell-5 {
@include grid-column(4, 1);
@include grid-row(2, 1);
}
.cell-6 {
@include grid-column(1, 3);
@include grid-row(3, 1);
}
.cell-7 {
@include grid-column(4, 1);
@include grid-row(3, 1);
}
.cell-8 {
@include grid-column(5, 2);
@include grid-row(1, 3);
}
.cell-9 {
@include grid-column(1, 6);
@include grid-row(4,1);
// paddend break out
margin-left : calc(50% - 50vw);
margin-right: calc(50% - 50vw);
padding-left : calc(50vw - 50% + 5px);
padding-right: calc(50vw - 50% );
background-color: dodgerblue;
color: white;
}
.cell-10 {
@include grid-column(1, 2);
@include grid-row(5,1);
}
.cell-11 {
@include grid-column(4, 3);
@include grid-row(5,1);
}
.cell-12 {
@include grid-column(3, 1);
@include grid-row(5,1);
}
.cell-13 {
@include grid-column(2, 4);
@include grid-row(6,1);
padding: 0;
// nested grid (TODO multi grid gaps for ie)
@include grid((cols: repeat(4), col-gap: 16px, row-gap: 8px));
// small grid
@media (max-width: 480px){
@include grid-column(1, 6);
@include grid((cols: repeat(12), col-gap: 16px, row-gap: 8px));
}
}
.cell-13a {
@include grid-column(1,1);
@include grid-row(1,8);
background: #666;
color: white;
// small grid layout
@media (max-width: 480px){ @include grid-cell(1, 8, 1,1);
}
}
.cell-13b {
@include grid-column(2,1);
@include grid-row(1, 1);
background: #666;
color: white;
// small grid layout
@media (max-width: 480px){ @include grid-cell(9, 2, 1, 1); }
}
.cell-13c {
@include grid-column(3,2);
@include grid-row(1,8);
background: #666;
color: white;
// small grid layout
@media (max-width: 480px){ @include grid-cell(11, 2, 1, 1); }
}
.cell-14 {
@include grid-column(1,6);
@include grid-row(7,1);
background-color: white;
font: 10px monospace;
overflow: auto;
padding: 16px;
span { color: #999; }
}
// simple css reset
html { box-sizing: border-box; }
*,*::before,*::after { bax-sizing: inherit; }
body {margin: 0; font-family: sans-serif; }
Also see: Tab Triggers