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.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="symbols">
<symbol id="symbol-test-1" viewBox="0 0 325 90" preserveAspectRatio="none">
<polygon points="325 45
288 90
0 90
0 0
288 0"/>
</symbol>
<!--
1. Beginning with base polygon shape, add an even stroke width with rounded joins.
2. Divide even stroke number by 2. So a stroke of 20 / 2 = 10
3. Add halved stroke number to both X and Y of viewBox coordinates.
4. Change all instances of 0 to halved stroke number.
5. Quarter stroke number and add this value to Y coordinate of middle point.
It's actually not necessary to use an even stroke, because we can use decimals.
It just makes the math easier and more intuitive.
To test that coordinates were properly shifted, set item margin-bottom to 1px.
They should be flush with 1px gap.
-->
<symbol id="symbol-test-2" viewBox="0 0 335 100" preserveAspectRatio="none">
<polygon points="325 50
288 90
10 90
10 10
288 10"
stroke-linejoin="round"
stroke-width="20"/>
</symbol>
<symbol id="symbol-test-3" viewBox="0 0 333 98" preserveAspectRatio="none">
<polygon points="325 49
288 90
8 90
8 8
288 8"
stroke-linejoin="round"
stroke-width="16"/>
</symbol>
<symbol id="symbol-test-4" viewBox="0 0 332 97" preserveAspectRatio="none">
<polygon points="325 48.5
288 90
7 90
7 7
288 7"
stroke-linejoin="round"
stroke-width="14"/>
</symbol>
<symbol id="symbol-test-5" viewBox="0 0 332 97" preserveAspectRatio="none">
<polygon points="325 48.5
288 90
7 90
7 7
288 7"
fill="black"
stroke="black"
stroke-linejoin="round"
stroke-width="14"/>
</symbol>
</svg>
<div id="test-1" class="item">
Mr. and Mrs. Dursley, of number four, Privet Drive, were proud to say that they were perfectly normal, thank you very much.
<svg>
<use xlink:href="#symbol-test-4"></use>
</svg>
</div>
<div id="test-2" class="item">
They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense.
<svg>
<use xlink:href="#symbol-test-4"></use>
</svg>
</div>
<div id="test-3" class="item">
Chapter 1
<svg>
<use xlink:href="#symbol-test-4"></use>
</svg>
</div>
<div id="test-4" class="item item-2">
They were the last people you'd expect to be involved in anything strange or mysterious, because they just didn't hold with such nonsense.
</div>
@color: #FFF;
.item
{
// transition: all 300ms linear;
display: flex;
box-sizing: border-box;
color: hsv(0, 0, 30%);
flex-flow: column wrap;
justify-content: center;
margin-bottom: 10px;
min-height: 90px;
padding: 20px 45px 20px 20px;
position: relative;
top: 0;
left: 0;
width: 325px;
&:hover
{
// There does appear to be some "stickiness"
// on this transform, especially if hovering
// quickly between the items. Doesn't happen
// if transition only exists on hover.
// Possibly due to referencing same symbol?
transform: translateX(20px);
transition: all 300ms linear;
}
svg
{
display: block;
fill: @color;
height: 100%;
opacity: 0.75;
position: absolute;
top: 0;
right: 0;
z-index: -1;
stroke: @color;
width: 100%;
}
}
// Why doesn't this work in Firefox? :(
// Sensitive to how SVG mark-up is crafted? That does seem to be where I'm having problems.
// Otherwise if it can work between browsers, this is a great solution.
// Major pro: can use CSS properties instead of SVG filters, which are far less
// intuitive to work with and change.
.item-2
{
background-color: rgba(255, 255, 255, 0.50);
box-shadow: inset 1px 1px 4px rgba(0, 0, 0, 0.10);
mask: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2aWV3Qm94PSIwIDAgMzMyIDk3IiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJub25lIj48cG9seWdvbiBwb2ludHM9IjMyNSA0OC41IDI4OCA5MCA3IDkwIDcgNyAyODggNyIgZmlsbD0iYmxhY2siIHN0cm9rZT0iYmxhY2siIHN0cm9rZS1saW5lam9pbj0icm91bmQiIHN0cm9rZS13aWR0aD0iMTQiLz4KPC9zdmc+') no-repeat 50% 50%;
}
body
{
background: hsv(0, 0, 93%);
margin: 1.000em;
}
#symbols
{
display: none;
}
Also see: Tab Triggers