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.
<svg xmlns="http://www.w3.org/2000/svg" style="width:0;height:0;visibility:hidden;"><symbol viewBox="0 0 280 280" id="completed-copy-filled"><title>completed-copy-filled</title> <path d="M245,24.5h-21v21c0,11.7-9.3,21-21,21s-21-9.3-21-21v-21H98v21c0,11.7-9.3,21-21,21s-21-9.3-21-21v-21H35
c-17.5,0-31.5,14-31.5,31.5v189c0,17.5,14,31.5,31.5,31.5h210c17.5,0,31.5-14,31.5-31.5V56C276.5,38.5,262.5,24.5,245,24.5z
M255.5,245c0,5.8-4.7,10.5-10.5,10.5H35c-5.8,0-10.5-4.7-10.5-10.5V87.5h229.8L255.5,245L255.5,245z"/> <g> <path d="M77,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5S66.5,8.2,66.5,14v31.5C66.5,52.5,71.2,56,77,56z"/> <path d="M203,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5S192.5,8.2,192.5,14v31.5C192.5,52.5,197.2,56,203,56z"/> </g> <g> <polygon points="198.3,120.2 191.3,114.3 186.7,119 173.8,130.7 171.5,134.2 159.8,145.8 148.2,157.5 135.3,169.2 123.7,182
112,193.7 92.2,172.7 86.3,168 79.3,173.8 68.8,184.3 79.3,194.8 92.2,207.7 103.8,219.3 112,227.5 122.5,217 129.5,210
134.2,205.3 147,193.7 158.7,182 170.3,169.2 186.7,152.8 198.3,141.2 208.8,130.7 "/> </g> </symbol><symbol viewBox="0 0 280 280" id="completed-copy-stroked-classes"><title>completed-copy-stroked-classes</title> <g> <path fill="none" stroke="#000000" stroke-miterlimit="10" d="M245,24.5h-21v21c0,11.7-9.3,21-21,21c-11.7,0-21-9.3-21-21v-21H98
v21c0,11.7-9.3,21-21,21s-21-9.3-21-21v-21H35c-17.5,0-31.5,14-31.5,31.5v189c0,17.5,14,31.5,31.5,31.5h210
c17.5,0,31.5-14,31.5-31.5V56C276.5,38.5,262.5,24.5,245,24.5z M255.5,245c0,5.8-4.7,10.5-10.5,10.5H35c-5.8,0-10.5-4.7-10.5-10.5
V87.5h229.8L255.5,245L255.5,245z"/> <path class="ibestrokin" fill="none" stroke="#000000" stroke-miterlimit="10" d="M77,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5
c-5.8,0-10.5,4.7-10.5,10.5v31.5C66.5,52.5,71.2,56,77,56z"/> <path class="ibestrokin" fill="none" stroke="#000000" stroke-miterlimit="10" d="M203,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5
c-5.8,0-10.5,4.7-10.5,10.5v31.5C192.5,52.5,197.2,56,203,56z"/> <polygon class="istrokeittotheeast" fill="none" stroke="#000000" stroke-miterlimit="10" points="198.3,120.2 191.3,114.3 186.7,119 173.8,130.7 171.5,134.2
159.8,145.8 148.2,157.5 135.3,169.2 123.7,182 112,193.7 92.2,172.7 86.3,168 79.3,173.8 68.8,184.3 79.3,194.8 92.2,207.7
103.8,219.3 112,227.5 122.5,217 129.5,210 134.2,205.3 147,193.7 158.7,182 170.3,169.2 186.7,152.8 198.3,141.2 208.8,130.7 "/> </g> </symbol><symbol viewBox="0 0 280 280" id="completed-copy-stroked"><title>completed-copy-stroked</title> <g> <path fill="none" stroke="#000000" stroke-miterlimit="10" d="M245,24.5h-21v21c0,11.7-9.3,21-21,21c-11.7,0-21-9.3-21-21v-21H98
v21c0,11.7-9.3,21-21,21s-21-9.3-21-21v-21H35c-17.5,0-31.5,14-31.5,31.5v189c0,17.5,14,31.5,31.5,31.5h210
c17.5,0,31.5-14,31.5-31.5V56C276.5,38.5,262.5,24.5,245,24.5z M255.5,245c0,5.8-4.7,10.5-10.5,10.5H35c-5.8,0-10.5-4.7-10.5-10.5
V87.5h229.8L255.5,245L255.5,245z"/> <path fill="none" stroke="#000000" stroke-miterlimit="10" d="M77,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5
c-5.8,0-10.5,4.7-10.5,10.5v31.5C66.5,52.5,71.2,56,77,56z"/> <path fill="none" stroke="#000000" stroke-miterlimit="10" d="M203,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5
c-5.8,0-10.5,4.7-10.5,10.5v31.5C192.5,52.5,197.2,56,203,56z"/> <polygon fill="none" stroke="#000000" stroke-miterlimit="10" points="198.3,120.2 191.3,114.3 186.7,119 173.8,130.7 171.5,134.2
159.8,145.8 148.2,157.5 135.3,169.2 123.7,182 112,193.7 92.2,172.7 86.3,168 79.3,173.8 68.8,184.3 79.3,194.8 92.2,207.7
103.8,219.3 112,227.5 122.5,217 129.5,210 134.2,205.3 147,193.7 158.7,182 170.3,169.2 186.7,152.8 198.3,141.2 208.8,130.7 "/> </g> </symbol><symbol viewBox="0 0 280 280" id="hand-filled"><title>hand-filled</title> <path fill="red" d="M245,24.5h-21v21c0,11.7-9.3,21-21,21s-21-9.3-21-21v-21H98v21c0,11.7-9.3,21-21,21s-21-9.3-21-21v-21H35
c-17.5,0-31.5,14-31.5,31.5v189c0,17.5,14,31.5,31.5,31.5h210c17.5,0,31.5-14,31.5-31.5V56C276.5,38.5,262.5,24.5,245,24.5z
M255.5,245c0,5.8-4.7,10.5-10.5,10.5H35c-5.8,0-10.5-4.7-10.5-10.5V87.5h229.8L255.5,245L255.5,245z"/> <g> <path d="M77,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5S66.5,8.2,66.5,14v31.5C66.5,52.5,71.2,56,77,56z"/> <path d="M203,56c5.8,0,10.5-4.7,10.5-10.5V14c0-5.8-4.7-10.5-10.5-10.5S192.5,8.2,192.5,14v31.5C192.5,52.5,197.2,56,203,56z"/> </g> <g> <polygon points="198.3,120.2 191.3,114.3 186.7,119 173.8,130.7 171.5,134.2 159.8,145.8 148.2,157.5 135.3,169.2 123.7,182
112,193.7 92.2,172.7 86.3,168 79.3,173.8 68.8,184.3 79.3,194.8 92.2,207.7 103.8,219.3 112,227.5 122.5,217 129.5,210
134.2,205.3 147,193.7 158.7,182 170.3,169.2 186.7,152.8 198.3,141.2 208.8,130.7 "/> </g> </symbol>
</svg>
<div>
<p>Originally filled. Easiest to work with. Simply apply fill/stroke as desired in CSS to the instance</p>
<svg class="filled-instance">
<use xlink:href="#completed-copy-filled" />
</svg>
</div>
<div>
<p>Originally stroked with no fill using [stroke] attribute in CSS to “reach-in” to the SVG</p>
<svg class="stroked-instance">
<use xlink:href="#completed-copy-stroked" />
</svg>
</div>
<div>
<p>Originally filled, but fill turned off</p>
<svg class="filled-instance-off">
<use xlink:href="#completed-copy-filled" />
</svg>
</div>
<div>
<p>Manually adding classes to the source SVG allows us to style to those in CSS</p>
<svg>
<use xlink:href="#completed-copy-stroked-classes" />
</svg>
</div>
<div>
<p>Hand Filled–Note that the part of the filled area that's been defined with a fill attribute (red), will NOT get overriden when we apply CSS to the SVG cloned instance. The parts that are working are cyan.</p>
<svg class="hand-filled-instance">
<use xlink:href="#hand-filled" />
</svg>
</div>
//Point 1. stroked instance is no longer styleable from instance
.stroked-instance {
stroke: green;//nothing happens
fill: red;//nada
}
//Point 2. but is from filled instance. Also, we can still apply a stroke
.filled-instance {
stroke: #cc8ac1;
stroke-width: 5px;
fill: lighten(#cc8ac1, 20%);
}
//Point 3. You can always achieve an outlined effect by simply "turning off" the fill
.filled-instance-off {
stroke: #d08aaf;
stroke-width: 5px;
fill: transparent;
}
//Point 4. If you want to apply stroke via CSS to the SVG exported with stroke and no fill, you have to target the shapes/paths within the source SVG in the defintion
symbol#completed-copy-stroked [stroke] {
stroke: #dd6435;
stroke-width: 5px;
}
//Point 5. You can also just add classes within the source SVG and apply CSS to those directly.
.ibestrokin {
stroke: magenta;
stroke-width: 5px;
}
.istrokeittotheeast {
stroke: green;
stroke-width: 7px;
}
//Point 6. Although we can override fill/stroke attributes from CSS if we apply that CSS directly to the definition, we cannot do via CSS applied to the instance
.hand-filled-instance {
fill: cyan; // the hard coded fill="red" path won't get affected by this!!!
//Note it doesn't matter if it's black fill="#000"...the black would remain
stroke: darken(red, 10%);
stroke-width: 5px;
}
Also see: Tab Triggers