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> CSS3 masking demo </h1>
<div class="instructions">
<label>
<input type="checkbox" checked onchange="ClipPathDemo.showInstructionsChanged()">
Show Instructions
</label>
<div id="instructionsContent">
<ul>
<li>
<b>Mask type:</b> The type of the mask. Masks may be based on clip-path with a basic shape, clip-path with an inlined SVG element, or mask-image. Also, masks may be static or animated.
</li>
<br>
<li>
<b>Maskee:</b> The content within the mask.
</li>
</ul>
</div>
</div>
<br>
<!-- Demo settings -->
<div class="setting">
<span class="setting-label"> Mask Type: </span>
<span>
<select id="maskShape" name="maskShape" onchange="ClipPathDemo.maskShapeChanged()">
<option value="none" autocomplete="off"> None </option>
<option value="rectangle" autocomplete="off">
clip-path | basic shape | Static Rectangle
</option>
<option value="rectangle-anim-reveal" autocomplete="off">
clip-path | basic shape | Rectangle Reveal
</option>
<option value="rectangle-anim-shrinkgrow" autocomplete="off">
clip-path | basic shape | Rectangle Shrink/Grow
</option>
<option value="circle" autocomplete="off">
clip-path | basic shape | Static Circle
</option>
<option value="circle-anim-oscillateresize" autocomplete="off">
clip-path | basic shape | Circle Oscillate and Resize
</option>
<option value="circle-anim-smalloscillate" autocomplete="off" selected>
clip-path | basic shape | Circle Small Oscillation
</option>
<option value="octagon" autocomplete="off">
clip-path | basic shape | Static Octagon
</option>
<option value="octagon-morph" autocomplete="off">
clip-path | basic shape | Octagon to Square
</option>
<option value="clipSVG" autocomplete="off">
clip-path | SVG | Static Star
</option>
<option value="clipSVG-anim" autocomplete="off">
clip-path | SVG | Star Animated (no effect!)
</option>
<option value="maskStar" autocomplete="off">
mask-image | Static Star
</option>
<option value="maskStar-reveal" autocomplete="off">
mask-image | Star Reveal
</option>
<option value="maskStar-shrinkgrow" autocomplete="off">
mask-image | Star Shrink/Grow
</option>
<option value="maskStar-oscillateresize" autocomplete="off">
mask-image | Star Oscillate and Resize
</option>
<option value="maskStar-smalloscillate" autocomplete="off">
mask-image | Star Small Oscillation
</option>
</select>
</span>
</div>
<div class="setting">
<span class="setting-label"> Maskee: </span>
<span>
<select id="maskee" name="maskee" onchange="ClipPathDemo.maskeeChanged()">
<option value="car" autocomplete="off" selected> Car </option>
<option value="car-animated" autocomplete="off"> Car (Animated) </option>
<option value="text" autocomplete="off"> Text </option>
</select>
</span>
</div>
<!-- Mask and maskee. -->
<div class="container">
<div class="mask clip-circle smalloscillate hide-overflow" id="Mask">
<img data-content-type="car" class="content selected" src="https://services.google.com/fh/files/misc/color_grey.jpg">
<img data-content-type="car-animated" class="content car-anim-3d" src="https://services.google.com/fh/files/misc/color_grey.jpg">
<div data-content-type="text" class="content">
<div class="text-background">
<div class="text">
Example Text
</div>
</div>
</div>
</div>
<!-- Unmasked content for reference -->
<div class="reference">
<img data-content-type="car" class="content selected" src="https://services.google.com/fh/files/misc/color_grey.jpg">
<img data-content-type="car-animated" class="content car-anim-3d" src="https://services.google.com/fh/files/misc/color_grey.jpg">
<div data-content-type="text" class="content">
<div class="text-background">
<div class="text">
Example Text
</div>
</div>
</div>
</div>
</div>
<!-- Inlined SVG for use with clip-path. -->
<svg height="0" width="0">
<defs>
<clipPath class="clip-svg-source" id="clipShapeStar">
<polygon points="150,10 90,198 240,78 60,78 210,198"
style="opacity:1;fill:#000000;" />
</clipPath>
</defs>
</svg>
/** Demo Settings */
.instructions {
font-size: 14px;
width: 800px;
}
.hidden {
display: none
}
.setting {
margin-bottom: 10px;
}
.setting-label {
margin-right: 10px;
}
/** Mask, maskee, and reference content. */
.container {
position: absolute;
transform-style: preserve-3d;
transform: perspective(1400px);
}
.container img {
width: 400px;
top: -50px;
}
.mask {
position: absolute;
left: 0px;
top: 20px;
width: 500px;
height: 500px;
}
.mask.hide-overflow {
/** If this is not set, clip-path is ignored if the maskee has 3D or animated transforms. */
overflow: hidden;
}
.content {
position: absolute;
left: 0px;
top: 0px;
display: none;
}
.content.selected {
display: block;
}
.reference {
position: absolute;
left: 500px;
top: 20px;
}
/** Clipping using basic shapes. */
.clip-rectangle {
clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
-webkit-clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
}
.clip-rectangle.reveal {
animation: clip_rectangle_reveal_keys 4s linear 0s infinite normal forwards;
-webkit-animation: clip_rectangle_reveal_keys 4s linear 0s infinite normal forwards;
}
@keyframes clip_rectangle_reveal_keys {
0% {
clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
-webkit-clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
}
50% {
clip-path: polygon(175px 0px, 175px 0px, 175px 200px, 175px 200px);
-webkit-clip-path: polygon(175px 0px, 175px 0px, 175px 200px, 175px 200px);
}
100% {
clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
-webkit-clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
}
}
.clip-rectangle.shrinkgrow {
animation: clip_rectangle_shrinkgrow_keys 4s linear 0s infinite normal forwards;
-webkit-animation: clip_rectangle_shrinkgrow_keys 4s linear 0s infinite normal forwards;
}
@keyframes clip_rectangle_shrinkgrow_keys {
0% {
clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
-webkit-clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
animation-timing-function: ease-in-out
}
50% {
clip-path: polygon(75px 0px, 275px 0px, 275px 200px, 75px 200px);
-webkit-clip-path: polygon(75px 0px, 275px 0px, 275px 200px, 75px 200px);
animation-timing-function: ease-in-out
}
100% {
clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
-webkit-clip-path: polygon(50px 0px, 300px 0px, 300px 200px, 50px 200px);
animation-timing-function: ease-in-out
}
}
.clip-circle {
clip-path: circle(100px at 150px 125px);
-webkit-clip-path: circle(100px at 150px 125px);
}
.clip-circle.oscillateresize {
animation: clip_circle_oscillateresize_keys 6s linear 0s infinite normal forwards;
-webkit-animation: clip_circle_oscillateresize_keys 6s linear 0s infinite normal forwards;
}
@keyframes clip_circle_oscillateresize_keys {
0% {
clip-path: circle(100px at 100px 100px);
-webkit-clip-path: circle(100px at 100px 100px);
}
50% {
clip-path: circle(0px at 300px 100px);
-webkit-clip-path: circle(0px at 300px 100px);
}
100% {
clip-path: circle(100px at 100px 100px);
-webkit-clip-path: circle(100px at 100px 100px);
}
}
.clip-circle.smalloscillate {
animation: clip_circle_smalloscillate_keys 4s linear 0s infinite normal forwards;
-webkit-animation: clip_circle_smalloscillate_keys 4s linear 0s infinite normal forwards;
}
@keyframes clip_circle_smalloscillate_keys {
0% {
clip-path: circle(100px at 150px 125px);
-webkit-clip-path: circle(100px at 150px 125px);
animation-timing-function: ease-in-out
}
50% {
clip-path: circle(100px at 170px 125px);
-webkit-clip-path: circle(100px at 170px 125px);
animation-timing-function: ease-in-out
}
100% {
clip-path: circle(100px at 100px 125px);
-webkit-clip-path: circle(100px at 150px 125px);
animation-timing-function: ease-in-out
}
}
.clip-octagon {
clip-path: polygon(50px 70px, 120px 0px, 220px 0px, 290px 70px, 290px 170px, 220px 240px, 120px 240px, 50px 170px);
-webkit-clip-path: polygon(50px 70px, 120px 0px, 220px 0px, 290px 70px, 290px 170px, 220px 240px, 120px 240px, 50px 170px);
}
.clip-octagon.morph {
animation: clip_octagon_morph_keys 4s linear 0s infinite normal forwards;
-webkit-animation: clip_octagon_morph_keys 4s linear 0s infinite normal forwards;
}
@keyframes clip_octagon_morph_keys {
0% {
clip-path: polygon(50px 70px, 120px 0px, 220px 0px, 290px 70px, 290px 170px, 220px 240px, 120px 240px, 50px 170px);
-webkit-clip-path: polygon(50px 70px, 120px 0px, 220px 0px, 290px 70px, 290px 170px, 220px 240px, 120px 240px, 50px 170px);
}
50% {
clip-path: polygon(120px 70px, 120px 70px, 220px 70px, 220px 70px, 220px 170px, 220px 170px, 120px 170px, 120px 170px);
-webkit-clip-path: polygon(120px 70px, 120px 70px, 220px 70px, 220px 70px, 220px 170px, 220px 170px, 120px 170px, 120px 170px);
}
100% {
clip-path: polygon(50px 70px, 120px 0px, 220px 0px, 290px 70px, 290px 170px, 220px 240px, 120px 240px, 50px 170px);
-webkit-clip-path: polygon(50px 70px, 120px 0px, 220px 0px, 290px 70px, 290px 170px, 220px 240px, 120px 240px, 50px 170px);
}
}
/** Clipping using an inlined SVG. */
.clip-svg {
-webkit-clip-path: url(#clipShapeStar);
clip-path: url(#clipShapeStar);
}
.clip-svg-source.anim {
animation: clip_svg_keys 2s linear 0s infinite normal forwards;
-moz-animation: clip_svg_keys 2s linear 0s infinite normal forwards;
-webkit-animation: clip_svg_keys 2s linear 0s infinite normal forwards;
}
@keyframes clip_svg_keys {
0% { transform: translate3d(0px, 0px, 0px); }
50% { transform: translate3d(0px, 100px, 0px); }
100% { transform: translate3d(0px, 0px, 0px); }
}
@-moz-keyframes clip_svg_keys {
0% { -moz-transform: translate3d(0px, 0px, 0px); }
50% { -moz-transform: translate3d(0px, 100px, 0px); }
100% { -moz-transform: translate3d(0px, 0px, 0px); }
}
@-webkit-keyframes clip_svg_keys {
0% { -webkit-transform: translate3d(0px, 0px, 0px); }
50% { -webkit-transform: translate3d(0px, 100px, 0px); }
100% { -webkit-transform: translate3d(0px, 0px, 0px); }
}
/** Masking. */
.mask-svg {
-webkit-mask-image: url(https://upload.wikimedia.org/wikipedia/commons/c/c8/Black_Star.svg);
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
-webkit-mask-repeat: no-repeat;
mask-image: url(https://upload.wikimedia.org/wikipedia/commons/c/c8/Black_Star.svg);
mask-position: 0px 0px;
mask-size: 300px 300px;
mask-repeat: no-repeat;
}
.mask-svg.reveal {
animation: mask_svg_reveal_keys 4s linear 0s infinite normal forwards;
-moz-animation: mask_svg_reveal_keys 4s linear 0s infinite normal forwards;
-webkit-animation: mask_svg_reveal_keys 4s linear 0s infinite normal forwards;
}
@keyframes mask_svg_reveal_keys {
0% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
}
50% {
-webkit-mask-position: 100px 0px;
-webkit-mask-size: 0px 300px;
mask-position: 100px 0px;
mask-size: 0px 300px;
}
100% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
}
}
.mask-svg.shrinkgrow {
animation: mask_svg_shrinkgrow_keys 3s linear 0s infinite normal forwards;
-moz-animation: mask_svg_shrinkgrow_keys 3s linear 0s infinite normal forwards;
-webkit-animation: mask_svg_shrinkgrow_keys 3s linear 0s infinite normal forwards;
}
@keyframes mask_svg_shrinkgrow_keys {
0% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
animation-timing-function: ease-in-out;
}
50% {
-webkit-mask-position: 10px 10px;
-webkit-mask-size: 280px 280px;
mask-position: 10px 10px;
mask-size: 280px 280px;
animation-timing-function: ease-in-out;
}
100% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
animation-timing-function: ease-in-out;
}
}
.mask-svg.smalloscillate {
animation: mask_svg_smalloscillate_keys 3s linear 0s infinite normal forwards;
-moz-animation: mask_svg_smalloscillate_keys 3s linear 0s infinite normal forwards;
-webkit-animation: mask_svg_smalloscillate_keys 3s linear 0s infinite normal forwards;
}
@keyframes mask_svg_smalloscillate_keys {
0% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
animation-timing-function: ease-in-out;
}
50% {
-webkit-mask-position: 20px 20px;
-webkit-mask-size: 300px 300px;
mask-position: 20px 20px;
mask-size: 300px 300px;
animation-timing-function: ease-in-out;
}
100% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
animation-timing-function: ease-in-out;
}
}
.mask-svg.oscillateresize {
animation: mask_svg_oscillateresize_keys 4s linear 0s infinite normal forwards;
-moz-animation: mask_svg_oscillateresize_keys 4s linear 0s infinite normal forwards;
-webkit-animation: mask_svg_oscillateresize_keys 4s linear 0s infinite normal forwards;
}
@keyframes mask_svg_oscillateresize_keys {
0% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
}
50% {
-webkit-mask-position: 300px 150px;
-webkit-mask-size: 1px 1px;
mask-position: 300px 0px;
mask-size: 1px 1px;
}
100% {
-webkit-mask-position: 0px 0px;
-webkit-mask-size: 300px 300px;
mask-position: 0px 0px;
mask-size: 300px 300px;
}
}
/** Maskee styling. */
.car-anim-3d {
animation: car_keys_3d 5s ease-in-out 0s infinite normal forwards;
-webkit-animation: car_keys_3d 5s ease-in-out 0s infinite normal forwards;
}
@keyframes car_keys_3d {
0% {
transform: rotateY(-30deg) translate3d(-50px, 0px, 0px);
-webkit-transform: rotateY(-30deg) translate3d(-50px, 0px, 0px);
}
50% {
transform: rotateY(30deg) translate3d(50px, 0px, 0px);
-webkit-transform: rotateY(30deg) translate3d(50px, 0px, 0px);
}
100% {
transform: rotateY(-30deg) translate3d(-50px, 0px, 0px);
-webkit-transform: rotateY(-30deg) translate3d(-50px, 0px, 0px);
}
}
.text-background {
position: absolute;
width: 340px;
height: 280px;
background-color: #c4c4c4;
}
.text {
position: absolute;
left: 50px;
top: 100px;
font-size: 40px;
}
window.ClipPathDemo = {};
/**
* Callback invoked when the clipping or masking shape has changed.
*/
ClipPathDemo.maskShapeChanged = function() {
var svgShape = document.getElementById('clipShapeStar');
var maskShape = document.getElementById('maskShape').value;
var mask = document.getElementById('Mask');
mask.classList.remove('hide-overflow');
mask.classList.remove('clip-svg');
mask.classList.remove('mask-svg');
mask.classList.remove('clip-rectangle');
mask.classList.remove('clip-circle');
mask.classList.remove('clip-octagon');
mask.classList.remove('anim');
mask.classList.remove('reveal');
mask.classList.remove('shrinkgrow');
mask.classList.remove('oscillate');
mask.classList.remove('smalloscillate');
mask.classList.remove('oscillateresize');
mask.classList.remove('morph');
svgShape.classList.remove('anim');
// Set the mask shape.
if (maskShape == 'clipSVG') {
mask.classList.add('clip-svg');
mask.classList.add('hide-overflow');
} else if (maskShape == 'clipSVG-anim') {
mask.classList.add('clip-svg');
mask.classList.add('anim');
mask.classList.add('hide-overflow');
} else if (maskShape == 'maskStar') {
mask.classList.add('mask-svg');
} else if (maskShape == 'maskStar-reveal') {
mask.classList.add('mask-svg');
mask.classList.add('reveal');
} else if (maskShape == 'maskStar-shrinkgrow') {
mask.classList.add('mask-svg');
mask.classList.add('shrinkgrow');
} else if (maskShape == 'maskStar-oscillateresize') {
mask.classList.add('mask-svg');
mask.classList.add('oscillateresize');
} else if (maskShape == 'maskStar-smalloscillate') {
mask.classList.add('mask-svg');
mask.classList.add('smalloscillate');
} else if (maskShape == 'rectangle') {
mask.classList.add('clip-rectangle');
mask.classList.add('hide-overflow');
} else if (maskShape == 'rectangle-anim-reveal') {
mask.classList.add('clip-rectangle');
mask.classList.add('reveal');
mask.classList.add('hide-overflow');
} else if (maskShape == 'rectangle-anim-shrinkgrow') {
mask.classList.add('clip-rectangle');
mask.classList.add('shrinkgrow');
mask.classList.add('hide-overflow');
} else if (maskShape == 'circle') {
mask.classList.add('clip-circle');
mask.classList.add('hide-overflow');
} else if (maskShape == 'circle-anim-oscillateresize') {
mask.classList.add('clip-circle');
mask.classList.add('oscillateresize');
mask.classList.add('hide-overflow');
} else if (maskShape == 'circle-anim-smalloscillate') {
mask.classList.add('clip-circle');
mask.classList.add('smalloscillate');
mask.classList.add('hide-overflow');
} else if (maskShape == 'octagon') {
mask.classList.add('clip-octagon');
mask.classList.add('hide-overflow');
} else if (maskShape == 'octagon-morph') {
mask.classList.add('clip-octagon');
mask.classList.add('morph');
mask.classList.add('hide-overflow');
}
};
/**
* Callback invoked when the selected maskee changes.
*/
ClipPathDemo.maskeeChanged = function() {
var maskeeName = document.getElementById('maskee').value;
var elems = document.querySelectorAll('.content');
for (var i = 0, len = elems.length; i < len; i++) {
if (elems[i].getAttribute('data-content-type') == maskeeName) {
elems[i].classList.add('selected');
} else {
elems[i].classList.remove('selected');
}
}
};
/**
* Callback invoked when the demo instructions are shown or hidden.
*/
ClipPathDemo.showInstructionsChanged = function() {
document.getElementById('instructionsContent').classList.toggle('hidden');
};
Also see: Tab Triggers