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.
.info.
Head on over to the CSS Editor and change the #[strong: code --option] Custom Property's value to a number #[strong between #[code 0] and #[code 9]].
mixin optionsAnimation(options, id, inherit = false)
- // variables
-
let i;
options = (typeof(options) === "number") ? options : 2;
if (typeof(id) !== "string") { id = `${id}`; }
if (typeof(id) === "string") { id = id.replace(/[^a-zA-Z0-9_-]/gi, ""); }
name = `options-${options}-${id}`;
- // writing comments
.
#{""}
/*
#{options}-Option Space Toggle Animation Set, ID #{id}
by Rock Starwind (@rockstarwind)
_______________________________________________________
#------------------------------------------------------
# * What is Space Toggle
#------------------------------------------------------
Popularized by @propjockey, Space Toggle is a technique
which, by assigning a space character to a custom property,
can arguably transform CSS into a programming language.
For a demo and a better explanation as to how it works,
be sure to read through @propjockey's "css-sweeper" repo.
https://github.com/propjockey/css-sweeper
The rest of the comments will assume you are familiar with
Space Toggles.
#------------------------------------------------------
# * The Properties
#------------------------------------------------------
▪ --#{name}_<num>-bool:
▫ Assigned `initial` by default.
▫ Later assigned a space character when the options
animation reaches a particular keyframe.
▫ <num> can be from 0 to #{options - 1}.
▪ --#{name}_<num>-nbool:
▫ Assigned a space character by default
▫ Later assigned `initial` when the options animation
reaches a particular keyframe.
▫ <num> can be from 0 to #{options - 1}.
▪ By default, the values of these properties are
#{inherit ? "" : "not " }capable of being inherited by the children
of any element in which this options animation
will be first used. Consider whether #{inherit ? "en" : "dis" }abling
inheritance by default aligns with the context
of their use.
#------------------------------------------------------
# * Setting it up (Shorthand Property)
# ** Fill mode depends on how/when you'd like to display fallbacks
# ** Replace <num> with option number (0 - #{options})
#------------------------------------------------------
animation: #{name} 1s calc(-1s * (<num> / #{options})) none linear normal 1 paused;
#------------------------------------------------------
# * Setting it up (Individual Properties)
# ** Fill mode depends on how/when you'd like to display fallbacks
# ** Replace <num> with option number (0 - #{options})
#------------------------------------------------------
animation-name: #{name};
animation-direction: normal;
animation-duration: 1s;
animation-delay: calc(-1s * (<num> / #{options}));
animation-fill-mode: none;
animation-iteration-count: 1;
animation-play-state: paused;
animation-timing-function: linear;
#------------------------------------------------------
# * Example (Basic)
# Change the "2" in calc(-1s * (2 / #{options})) to see
# how the background color property is affected.
#------------------------------------------------------
animation: #{name} 1s calc(-1s * (2 / #{options})) both linear normal 1 paused;
--background_is-#{name}_2: var(--#{name}_2-bool) #0F0;
background: var(--background_is-#{name}_2, #F00);
*/
- // registering properties
- i = 0
while (i <= options)
.
@property --#{name}_#{i}-bool {
syntax: "*";
inherits: #{inherit};
initial-value: initial;
}
@property --#{name}_#{i}-nbool {
syntax: "*";
inherits: #{inherit};
initial-value: ;
}
- i++
- // creating animation
- i = 0
- // start of keyframe animation
| @keyframes #{name} {
|
while (i < options)
- // keyframe percentages
| #{100 * (i / options)}%,
if (i < options - 1)
| #{(100 * ((i + 1) / options)) - .1}%
if (i === options - 1)
| 100%
- // start of declaration block
| {
| --#{name}_#{i}-bool: ;
| --#{name}_#{i}-nbool: initial;
|
- // if i > 0
if (i > 0)
| --#{name}_#{i - 1}-bool: initial;
| --#{name}_#{i - 1}-nbool: ;
|
- // end of declaration block
| }
- // odd formatting
if (i < options)
.
#{""}
- i++ // iterate
- // end of keyframe animation
|
|}
style(type="text/css")
.
@property --annie { syntax: "*"; inherits: false; }
html * { animation: var(--annie); }
#[+optionsAnimation(10, 1, false)]
:root {
--option: 1;
}
@import url("https://fonts.googleapis.com/css?family=Lato:400,400i,700");
@import url("https://fonts.googleapis.com/css?family=Inconsolata:400,400i,700");
html, body {
display: flex;
flex: 1;
flex-direction: column;
font-family: Lato, Helvetica, "Segoe UI", Arial, system-ui, sans-serif;
margin: 0;
min-height: 100%;
padding: 0;
}
body {
align-items: center;
justify-content: center;
}
code {
font-family: inconsolata, consolas, monospace;
}
/*
The magic
Backgrounds 0-9 were created by Lea Verou
http://projects.verou.me/css3patterns/
*/
body {
--annie: options-10-1 1s calc(-1s * (var(--option) / 10)) none linear normal 1 paused;
--background_is-options-10-1_0:
/* if option-10-1 === 0 */
var(--options-10-1_0-bool)
/* display this */
radial-gradient(circle at 100% 50%, transparent 20%, rgba(255,255,255,.3) 21%, rgba(255,255,255,.3) 34%, transparent 35%, transparent) 0 0/75px 100px,
radial-gradient(circle at 0% 50%, transparent 20%, rgba(255,255,255,.3) 21%, rgba(255,255,255,.3) 34%, transparent 35%, transparent) 0 -50px/75px 100px,
slategray
;
--background_is-options-10-1_1:
/* if option-10-1 === 1 */
var(--options-10-1_1-bool)
radial-gradient(closest-side, transparent 98%, rgba(0,0,0,.3) 99%) 0 0/80px 80px,
radial-gradient(closest-side, transparent 98%, rgba(0,0,0,.3) 99%) 40px 40px/80px 80px,
#def
;
--background_is-options-10-1_2:
/* if option-10-1 === 2 */
var(--options-10-1_2-bool)
linear-gradient(90deg, rgba(200,0,0,.5) 50%, transparent 50%) center/50px 50px,
linear-gradient(rgba(200,0,0,.5) 50%, transparent 50%) center/50px 50px
;
--background_is-options-10-1_3:
/* if option-10-1 === 3 */
var(--options-10-1_3-bool)
linear-gradient(30deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445) 0 0/80px 140px,
linear-gradient(150deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445) 0 0/80px 140px,
linear-gradient(30deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445) 40px 70px/80px 140px,
linear-gradient(150deg, #445 12%, transparent 12.5%, transparent 87%, #445 87.5%, #445) 40px 70px/80px 140px,
linear-gradient(60deg, #99a 25%, transparent 25.5%, transparent 75%, #99a 75%, #99a) 0 0/80px 140px,
linear-gradient(60deg, #99a 25%, transparent 25.5%, transparent 75%, #99a 75%, #99a) 40px 70px/80px 140px,
#556
;
--background_is-options-10-1_4:
/* if option-10-1 === 4 */
var(--options-10-1_4-bool)
radial-gradient(circle, transparent 20%, slategray 20%, slategray 80%, transparent 80%, transparent) 0px 0px/100px 100px,
radial-gradient(circle, transparent 20%, slategray 20%, slategray 80%, transparent 80%, transparent) 50px 50px/100px 100px,
linear-gradient(#A8B1BB 8px, transparent 8px) 0 -4px/50px 50px,
linear-gradient(90deg, #A8B1BB 8px, transparent 8px) -4px 0/50px 50px,
slategray
;
--background_is-options-10-1_5:
/* if option-10-1 === 5 */
var(--options-10-1_5-bool)
radial-gradient(circle at 100% 150%, silver 24%, white 24%, white 28%, silver 28%, silver 36%, white 36%, white 40%, transparent 40%, transparent) center/100px 50px,
radial-gradient(circle at 0 150%, silver 24%, white 24%, white 28%, silver 28%, silver 36%, white 36%, white 40%, transparent 40%, transparent) center/100px 50px,
radial-gradient(circle at 50% 100%, white 10%, silver 10%, silver 23%, white 23%, white 30%, silver 30%, silver 43%, white 43%, white 50%, silver 50%, silver 63%, white 63%, white 71%, transparent 71%, transparent) center/100px 50px,
radial-gradient(circle at 100% 50%, white 5%, silver 5%, silver 15%, white 15%, white 20%, silver 20%, silver 29%, white 29%, white 34%, silver 34%, silver 44%, white 44%, white 49%, transparent 49%, transparent) center/100px 50px,
radial-gradient(circle at 0 50%, white 5%, silver 5%, silver 15%, white 15%, white 20%, silver 20%, silver 29%, white 29%, white 34%, silver 34%, silver 44%, white 44%, white 49%, transparent 49%, transparent) center/100px 50px,
silver
;
--background_is-options-10-1_6:
/* if option-10-1 === 6 */
var(--options-10-1_6-bool)
radial-gradient(#DDD 15%, transparent 16%) 0 0/60px 60px,
radial-gradient(#DDD 15%, transparent 16%) 30px 30px/60px 60px
#FFF
;
--background_is-options-10-1_7:
/* if option-10-1 === 7 */
var(--options-10-1_7-bool)
radial-gradient(circle at 50% 59%, #D2CAAB 3%, #364E27 4%, #364E27 11%, rgba(54,78,39,0) 12%, rgba(54,78,39,0)) 50px 0/100px 100px,
radial-gradient(circle at 50% 41%, #364E27 3%, #D2CAAB 4%, #D2CAAB 11%, rgba(210,202,171,0) 12%, rgba(210,202,171,0)) 50px 0/100px 100px,
radial-gradient(circle at 50% 59%, #D2CAAB 3%, #364E27 4%, #364E27 11%, rgba(54,78,39,0) 12%, rgba(54,78,39,0)) 0 50px/100px 100px,
radial-gradient(circle at 50% 41%, #364E27 3%, #D2CAAB 4%, #D2CAAB 11%, rgba(210,202,171,0) 12%, rgba(210,202,171,0)) 0 50px/100px 100px,
radial-gradient(circle at 100% 50%, #D2CAAB 16%, rgba(210,202,171,0) 17%) 0 0/100px 100px,
radial-gradient(circle at 0% 50%, #364E27 16%, rgba(54,78,39,0) 17%) 0 0/100px 100px,
radial-gradient(circle at 100% 50%, #D2CAAB 16%, rgba(210,202,171,0) 17%) 50px 50px/100px 100px,
radial-gradient(circle at 0% 50%, #364E27 16%, rgba(54,78,39,0) 17%) 50px 50px/100px 100px,
#63773F
;
--background_is-options-10-1_8:
/* if option-10-1 === 8 */
var(--options-10-1_8-bool)
radial-gradient(white, rgba(255,255,255,.2) 2px, transparent 40px) 0 0/550px 550px,
radial-gradient(white, rgba(255,255,255,.15) 1px, transparent 30px) 40px 60px/350px 350px,
radial-gradient(white, rgba(255,255,255,.1) 2px, transparent 40px) 130px 270px/250px 250px,
radial-gradient(rgba(255,255,255,.4), rgba(255,255,255,.1) 2px, transparent 30px) 70px 100px/150px 150px,
#000
;
--background_is-options-10-1_9:
/* if option-10-1 === 9 */
var(--options-10-1_9-bool)
radial-gradient(circle closest-side at 60% 43%, #b03 26%, rgba(187,0,51,0) 27%) 0 0/100px 100px,
radial-gradient(circle closest-side at 40% 43%, #b03 26%, rgba(187,0,51,0) 27%) 0 0/100px 100px,
radial-gradient(circle closest-side at 40% 22%, #d35 45%, rgba(221,51,85,0) 46%) 0 0/100px 100px,
radial-gradient(circle closest-side at 60% 22%, #d35 45%, rgba(221,51,85,0) 46%) 0 0/100px 100px,
radial-gradient(circle closest-side at 50% 35%, #d35 30%, rgba(221,51,85,0) 31%) 0 0/100px 100px,
radial-gradient(circle closest-side at 60% 43%, #b03 26%, rgba(187,0,51,0) 27%) 50px 50px/100px 100px,
radial-gradient(circle closest-side at 40% 43%, #b03 26%, rgba(187,0,51,0) 27%) 50px 50px/100px 100px,
radial-gradient(circle closest-side at 40% 22%, #d35 45%, rgba(221,51,85,0) 46%) 50px 50px/100px 100px,
radial-gradient(circle closest-side at 60% 22%, #d35 45%, rgba(221,51,85,0) 46%) 50px 50px/100px 100px,
radial-gradient(circle closest-side at 50% 35%, #d35 30%, rgba(221,51,85,0) 31%) 50px 50px/100px 100px
#B03
;
background:
/* think of this as a series of ifs and else ifs */
var(--background_is-options-10-1_0,
var(--background_is-options-10-1_1,
var(--background_is-options-10-1_2,
var(--background_is-options-10-1_3,
var(--background_is-options-10-1_4,
var(--background_is-options-10-1_5,
var(--background_is-options-10-1_6,
var(--background_is-options-10-1_7,
var(--background_is-options-10-1_8,
var(--background_is-options-10-1_9,
/* this is the else */
linear-gradient(to bottom, #000, #FFF, #000)
)
)
)
)
)
)
)
)
)
)
;
}
.info {
background: #fff;
box-shadow: .5em 1em 1.5em rgba(#000, .5);
box-sizing: border-box;
margin: 1em;
max-width: 960px;
padding: 1em;
& strong {
white-space: nowrap;
}
}
// ¯\_(ツ)_/¯
Also see: Tab Triggers