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.
# SusyCSS: *Susy without Sass*
This is a near-complete implementation of
[Susy 3](https://github.com/oddbird/susy/releases/tag/3.0.0.alpha.1),
built entirely with CSS Variables (custom properties).
[Check out the Demo »](https://codepen.io/mirisuzanne/pen/PboVrw?editors=0100)
(this pen is intentionally unstyled,
containing only CSS variables,
so that it can be pasted anywhere)
---
## Global Settings
These variables should be set
on the `:root` element,
so that they inherit.
- `--susy-columns: 4;`
» [integer]
*available columns on the grid*
- `--susy-gutters: 0.25;`
» [number]
*relative size of a gutter to a column*
- `--susy-spread: 0;`
» [-1 | 0 | 1]
*number of span gutters in relation to columns*
- `--susy-container-spread: 0;`
» [-1 | 0 | 1]
*number of container gutters in relation to columns*
- `--susy-debug-color: hsla(0, 0%, 0%, 0.125);`
» [color]
*used to show columns when debugging*
For fully-static grids, set `--susy-static-grid`.
For static-gutters on an otherwise fluid grid,
set `--susy-static-gutters`.
If either value is true,
make sure you set the desired column-width.
- `--susy-static-grid: 0;`
» [boolean]
*0 for fluid (%) output, 1 for static (based on column-width)*
- `--susy-static-gutters: var(--susy-static-grid);`
» [boolean]
*0 for fluid (%) gutters, 1 for static (based on column-width)*
- `--susy-column-width: 5em;`
» [length]
*width of one column, when using static output*
## Returned Values
These variables represent Susy's output —
like the return value from a Sass function.
They can be applied to any property,
or used inside `calc()`
for more complex math.
Don't set these, just use them!
- `--span-width` (`--fluid-span` / `--static-span`)
» *default, static, or fluid width for current span*
- `--gutter-width` (`--fluid-gutters` / `--static-gutters`)
» *default, static or fluid width for current gutters*
- `--container`
» *static width of the current columns context*
## "Mixins"
These variables work like mixins,
automatically applying returned values
to specific properties.
- `--span: initial;`
» [integer]
*used to calculate the local value of `span-width`,
and automatically applied to the `width` property.*
- `--gutters-inside: 0;`
» [number]
*any number of gutter-widths to apply as left/right padding*
- `--gutters-left: 0;`
» [number]
*any number of gutter-widths to apply as left margin*
- `--gutters-right: 0;`
» [number]
*any number of gutter-widths to apply as right margin*
## Debug Values
These values need to be used together,
applied to the `background` and `background-size`
properties respectively.
- `--debug-image` / `--debug-image-split`
» *apply to `background` or `background-image` property
to generate a gradient representing one column/gutter pair —
use `-split` if you want half a column on each side.*
- `--debug-image-size`
» *apply to `background-size` property
in order to scale the background-gradient down,
so it repeats properly across the grid.*
As always,
the background grid gradient for debugging
doesn't handle sub-pixel rounding.
That's nothing new.
Maybe we could build an inline-svg background
using custom properties as well?
Something to try!
---
## Advantages
1. SusyCSS understands the DOM structure! *Settings actually inherit*!
2. No Sass required!
## Limitations
1. CSS has no necessary control structures,
so the syntax & settings are bulkier.
2. SusyCSS doesn't support asymmetrical grids.
3. Within the context of a single selector,
each variable can only have a single value.
There is no way to pass different arguments.
4. Why build this much flexibility into a single code base?
## ToDo:
1. Can we make an inline-svg grid image?
:root {
/* "--susy-" variables establish the grid */
/* settings will inherit... */
--susy-columns: 4;
--susy-gutters: 0.25;
--susy-spread: 0;
--susy-container-spread: 0;
--susy-debug-color: hsla(0, 0%, 0%, 0.125);
/* for static grids only */
--susy-static-grid: 0; /* boolean */
--susy-static-gutters: var(--susy-static-grid); /* boolean */
--susy-column-width: 5em;
}
* {
/* ...but all the math has to happen on the element. */
/* INTERNAL MATH */
/* ------------- */
/* container math */
---su-container-sum: calc(
var(--susy-columns) +
(
( var(--susy-columns) + var(--susy-container-spread) )
* var(--susy-gutters)
)
);
/* span math */
---su-span-sum: calc(
var(--span) +
(
( var(--span) + var(--susy-spread) )
* var(--susy-gutters)
)
);
/* gutter output math */
---su-inside-gutters: calc(
var(--gutter-width) * var(--gutters-inside)
);
---su-gutters-left: calc(
var(--gutter-width) * var(--gutters-left)
);
---su-gutters-right: calc(
var(--gutter-width) * var(--gutters-right)
);
/* background grid math */
---su-grid-image-sum: calc(
1 + var(--susy-gutters)
);
---su-grid-gutter-ratio: calc(
var(--susy-gutters) / var(---su-grid-image-sum) * 100%
);
---su-split-gutter-ratio: calc(
var(---su-grid-gutter-ratio) / 2
);
/* PUBLIC FUNCTIONS */
/* ---------------- */
/* span functions */
--fluid-span: calc(
var(---su-span-sum) / var(---su-container-sum) * 100%
);
--static-span: calc(
var(---su-span-sum) * var(--susy-column-width)
);
--span-width: calc(
var(--static-span) * var(--susy-static-grid) +
var(--fluid-span) * (1 - var(--susy-static-grid))
);
/* container functions */
--container-width: calc(
var(---su-container-sum) * var(--susy-column-width)
);
/* gutter functions */
--fluid-gutters: calc(
var(--susy-gutters) / var(---su-container-sum) * 100%
);
--static-gutters: calc(
var(--susy-gutters) * var(--susy-column-width)
);
--gutter-width: calc(
var(--static-gutters) * var(--susy-static-gutters) +
var(--fluid-gutters) * (1 - var(--susy-static-gutters))
);
/* debug functions */
--debug-image: linear-gradient(to right,
var(--susy-debug-color, #ccc) calc(100% - var(---su-grid-gutter-ratio)),
transparent calc(100% - var(---su-grid-gutter-ratio)));
--debug-image-split: linear-gradient(to right,
transparent var(---su-split-gutter-ratio),
var(--susy-debug-color, #ccc) var(---su-split-gutter-ratio),
var(--susy-debug-color, #ccc) calc(100% - var(---su-split-gutter-ratio)),
transparent calc(100% - var(---su-split-gutter-ratio)));
--debug-image-size: calc(
var(---su-grid-image-sum) / var(---su-container-sum) * 100%
);
/* PUBLIC MIXINS */
/* ------------- */
--span: initial; /* integer */
--gutters-inside: 0; /* multiplier */
--gutters-left: 0; /* multiplier */
--gutters-right: 0; /* multiplier */
/* output */
width: var(--span-width, initial);
padding-left: var(---su-inside-gutters, initial);
padding-right: var(---su-inside-gutters, initial);
margin-left: var(---su-gutters-left, initial);
margin-right: var(---su-gutters-right, initial);
}
Also see: Tab Triggers