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.
<h1>Linear vs. Paced vs. Discrete SVG/SMIL Animation</h1>
<svg width="100%" height="100%" viewBox="0 0 600 600" preserveAspectRatio="xMidYMin meet">
<g id="graphics" font-size="30">
<rect width="100%" height="100%" fill="lightyellow"/>
<g>
<circle cx="50" cy="100" r="100" fill="gray">
<animate attributeName="cx" attributeType="XML"
begin="0;graphics.click"
values="50;500;300;400;50"
dur="20s"
calcMode="linear" />
<animate attributeName="fill" attributeType="XML"
begin="0;graphics.click"
dur="20s"
values="gray;darkred;red;cyan;lightcyan;green;purple;gray"
calcMode="linear" />
</circle>
<text x="50" y="100">linear</text>
</g>
<g>
<circle cx="50" cy="300" r="100" fill="gray">
<animate attributeName="cx" attributeType="XML"
begin="0;graphics.click"
values="50;500;300;400;50"
dur="20s"
calcMode="paced"/>
<animate attributeName="fill" attributeType="XML"
begin="0;graphics.click"
dur="20s"
values="gray;darkred;red;cyan;lightcyan;green;purple;gray"
calcMode="paced" />
</circle>
<text x="50" y="300">paced</text>
</g>
<g>
<circle cx="50" cy="500" r="100" fill="gray">
<animate attributeName="cx" attributeType="XML"
begin="0;graphics.click"
values="50;500;300;400;50"
dur="20s"
calcMode="discrete" />
<animate attributeName="fill" attributeType="XML"
begin="0;graphics.click"
dur="20s"
values="gray;darkred;red;cyan;lightcyan;green;purple;gray"
calcMode="discrete" />
</circle>
<text x="50" y="500">discrete</text>
</g>
</g>
</svg>
<strong>Click the SVG to restart the animations.</strong>
<p>The SVG/SMIL <code>calcMode</code> attribute on animation elements defines how to interpolate between multiple values in a single animation.
</p>
<p><b>Linear</b> animation (the default) divides up the time evenly between multiple specified values, and then progresses between each stop point in an even manner. So if you have 5 values, the time will be divided into 4 transitions between each successive pair of values. You can specify different timings with a <code>keyTimes</code> attribute, but each step will still interpolate linearly. For <code>keyTimes</code>, use another semi-colon separated list with the same number of entries as your <code>values</code> list. The first time must be 0 and the last time 1; other times are given as decimals (representing a proportion of total time), in numerical order.
</p>
<p><b>Paced</b> animation calculates the distance between each values, and divides up the time accordingly to create an even speed of change throughout the entire animation. Key times are ignored. Only certain types of values can be paced: colours or simple numbers/lengths. You can't pace a path or a dasharray, for example, because there's no clear way to compare the "distances" between two sets of values.
</p>
<p><b>Discrete</b> animation jumps from one value to the next. By default it spends equal time on each, but you can change that with <code>keyTimes</code>. Note that for discrete animation—unlike linear—a list of 5 values result in 5 time periods. The <code>keyTimes</code> values are the start time of each setting, so while the first time still has to be zero, the last time does not have to be 1.
</p>
<p><b>Spline</b> animation (not shown) allows you to change the rate at which the animation transitions between two values. The time devoted to each stage of the animation is divided the same as for linear animation. A <code>keySplines</code> attribute defines the easing function for each transition.</p>
Also see: Tab Triggers