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 = {
- function: [ 'round', 'mod', 'rem', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'atan2', 'pow', 'sqrt', 'exp', 'log', 'hypot', 'abs', 'sign' ],
- constant: ['e', 'pi', 'infinity', '-infinity']
- };
p Confused about what browser supports what mathematical functions/ constants? This Pen uses
code @supports
| to tell you what the browser you're currently viewing it in supports and what not.
p As of April 2023, Safari (tested via Epiphany as I'm on Ubuntu) supports everything, Firefox 113 supports everything except
code abs()
| and
code sign()
| (which can be easily
a(href='https://css-tricks.com/using-absolute-value-sign-rounding-and-modulo-in-css-today/' target='_blank') emulated
| using other very well supported functions though), while Chrome 111+ only supports constants and trigonometric functions. Plus
code abs()
| and
code sign()
| starting with version 113, as well as all the others starting with version 115, even if only behind the
b Experimental Web Platform features
| flag (which can be enabled from
code chrome://flags
| ).
- for(let p in data)
- let a = data[p], n = a.length;
- for(let i = 0; i < n; i++)
- let c = a[i];
- let cond = p === 'function';
- let url = cond ? 'funcdef' : 'valdef-calc'
.box(data-feat=`${p}--${c}` data-test='1') Yay, your browser supports the
a(href=`https://drafts.csswg.org/css-values-4/#${url}-${c}` target='_blank')
code #{c}#{cond ? '()' : ''}
| #{p}! π₯³ π
.box(data-feat=`${p}--${c}`) Sorry, your browser does not support the
a(href=`https://drafts.csswg.org/css-values-4/#${url}-${c}` target='_blank')
code #{c}#{cond ? '()' : ''}
| #{p}. πΏ
footer
p The info boxes were created as described in
a(href='https://codepen.io/thebabydino/full/qBKvjKM' target='_blank') this Pen
| .
p Got any other questions about this? Found any problems with it?
br
| You can drop a comment
a(href='https://codepen.io/thebabydino/details/yLRBJXP' target='_blank') here
| or ping me on
a(href='https://mastodon.social/@anatudor' target='_blank' data-ico='π¦£') Mastodon
|
| or on
a(href='https://twitter.com/anatudor' target='_blank' data-ico='π¦') Twitter
| .
p And if you like the Maths and Physics infused CSS, canvas and SVG work that I've been putting out for over a decade, you can support it by being a cool cat and becoming a patron on
a(href='https://www.patreon.com/anatudor' target='_blank') Patreon
| or with a one time donation on
a(href='https://ko-fi.com/anatudor' target='_blank') Ko-fi
| . Or at least by sharing this to show the world what can be done with CSS these days... because it's pretty damn cool!
$s: 4px;
/* ----- relevant styles ----- */
.box {
/* here's where the cool part starts:
* different styles for the yay/ nay boxes */
border-left: solid 5px #db3056;
background: #851d41;
/* a value of 1 if it indicates feature is supported */
&[data-test='1'] {
border-color: #4e8d7c;
background: #045762;
display: none
}
/* ----- THE MAGIC ----- */
/* support test for the round() function */
@supports (z-index: Round(4.1*.5, 1)) {
&[data-feat='function--round'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the mod() function */
@supports (z-index: Mod(5, 2)) {
&[data-feat='function--mod'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the rem() function */
@supports (z-index: Rem(5, 2)) {
&[data-feat='function--rem'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the sin() function */
@supports (top: calc(sin(45deg)*1em)) {
&[data-feat='function--sin'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the cos() function */
@supports (top: calc(cos(45deg)*1em)) {
&[data-feat='function--cos'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the tan() function */
@supports (top: calc(tan(45deg)*1em)) {
&[data-feat='function--tan'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the asin() function */
@supports (rotate: asin(.5)) {
&[data-feat='function--asin'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the acos() function */
@supports (rotate: acos(.5)) {
&[data-feat='function--acos'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the atan() function */
@supports (rotate: atan(.5)) {
&[data-feat='function--atan'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the atan2() function */
@supports (rotate: atan2(4, 3)) {
&[data-feat='function--atan2'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the pow() function */
@supports (z-index: pow(2, 2)) {
&[data-feat='function--pow'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the sqrt() function */
@supports (z-index: Sqrt(4)) {
&[data-feat='function--sqrt'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the exp() function */
@supports (top: calc(Exp(2)*1em)) {
&[data-feat='function--exp'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the log() function */
@supports (top: calc(Log(4, 2)*1em)) {
&[data-feat='function--log'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the hypot() function */
@supports (top: Hypot(4em, 3em)) {
&[data-feat='function--hypot'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the abs() function */
@supports (z-index: Abs(-5)) {
&[data-feat='function--abs'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the sign() function */
@supports (z-index: Sign(-5)) {
&[data-feat='function--sign'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the e constant */
@supports (top: calc(e*1em)) {
&[data-feat='constant--e'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the pi constant */
@supports (rotate: calc(.25turn*pi)) {
&[data-feat='constant--pi'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the infinity constant */
@supports (rotate: atan(infinity)) {
&[data-feat='constant--infinity'] {
display: none;
&[data-test='1'] { display: block }
}
}
/* support test for the -infinity constant */
@supports (rotate: atan(-infinity)) {
&[data-feat='constant---infinity'] {
display: none;
&[data-test='1'] { display: block }
}
}
}
/* ----- all the prettifying, less important styles ----- */
body {
box-sizing: border-box;
margin: 0 auto;
max-width: 47em;
padding: .5em;
background: #262434;
color: #fff;
font: 1.25em/ 1.3 ubuntu, trebuchet ms, sans-serif
}
a {
--hl: 0;
position: relative;
z-index: 1;
padding: 0 .5*$s;
color: gold;
text-decoration: none;
isolation: isolate;
&::before {
position: absolute;
inset: 0;
transform-origin: 0 100%;
transform: scaley(calc(var(--hl) - .1*(1 - var(--hl))));
background: currentcolor;
mix-blend-mode: difference;
transition: transform .35s ease-out;
content: ''
}
&:focus { outline: none }
&:hover, &:focus { --hl: 1 }
}
[data-ico] {
margin-right: 1.5em;
&::after {
position: absolute;
left: calc(100% + 2px);
content: ' ' attr(data-ico)
}
}
div {
position: relative;
margin: .375em 0;
padding: .25em .5em;
box-shadow: 0 2px 5px -2px #141414,
0 5px 13px -5px #040404
}
code {
font-family: ubuntu mono, consoas, monaco, monospace;
font-size: 1.125em
}
footer {
font-size: .75em;
text-align: center
}
Also see: Tab Triggers