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>Updated Video Facade Demo</h1>
<div
class="videoEmbed vimeo"
style="--aspect-ratio:16/9; --video-poster:url(https://i.vimeocdn.com/video/1629179233-07cd02cf6c34fc8b4181493ecda0619132f837289758854ee346a6f3c0e3525e-d?mw=1280&mh=720&q=70)"
>
<header>Ren - Hi Ren český překlad from SenseOfHipHop</header>
<a href="https://vimeo.com/806825926" target="_blank">
<span>Watch On <b>Vimeo</b></span>
</a>
</div>
<div
class="videoEmbed youtube"
style="--aspect-ratio:4/3; --video-poster:url(https://img.youtube.com/vi/G66KL-hxxKI/hqdefault.jpg)"
>
<header>LGR - Paku Paku - DOS PC Game Review</header>
<a href="https://youtu.be/G66KL-hxxKI" target="_blank">
<span>Watch on <b>YouTube</b></span>
</a>
</div>
<div
class="videoEmbed youtube"
style="--aspect-ratio:4/3; --video-poster:url(https://img.youtube.com/vi/8Jg346R5wbk/hqdefault.jpg)"
>
<header>Honcho - Mig-15 vs. Five F-86</header>
<a href="https://www.youtube.com/watch?v=8Jg346R5wbk" target="_blank">
<span>Watch on <b>YouTube</b></span>
</a>
<div>
body {
max-width:48rem;
margin:auto;
padding:1rem;
}
h1 {
margin:0;
}
.videoEmbed {
position:relative;
overflow:hidden;
aspect-ratio:var(--aspect-ratio);
max-height:90vh;
margin:1rem auto;
font-family:arial,helvetica,sans-serif;
background-color:#000;
background-image:var(--video-poster);
background-size:contain;
}
.videoEmbed > * {
box-sizing:border-box;
position:absolute;
left:0;
top:0;
width:100%;
height:100%;
border:0;
}
.videoEmbed a span {
position:absolute;
left:0;
bottom:1rem;
z-index:99;
padding:1rem;
line-height:1.5rem;
text-decoration:none;
background:#222;
color:#EEE;
transition:background 0.3s;
}
.videoEmbed a:focus span,
.videoEmbed a:hover span {
background:#444;
}
.videoEmbed a b,
.videoEmbed button {
background-color:transparent;
color:transparent;
cursor:pointer;
}
.videoEmbed button {
background:center no-repeat;
transition:scale 0.3s;
}
.videoEmbed button:focus,
.videoEmbed button:hover {
scale:1.1;
}
.videoEmbed header {
padding:0.5rem;
color:#FFF;
text-shadow:
-0.0625em -0.0625em 0.125em #000,
0.0625em -0.0625em 0.125em #000,
0.0625em 0.0625em 0.125em #000,
-0.0625em 0.0625em 0.125em #000,
0 0 0.25em #000;
}
.videoEmbed a b {
display:inline-block;
font-size:1.25em;
vertical-align:top;
background:center no-repeat;
background-size:contain;
}
.videoEmbed.vimeo span {
background:#025;
}
.videoEmbed.vimeo a:focus span,
.videoEmbed.vimeo a:hover span {
background:#008;
}
.videoEmbed.vimeo button {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 512 512' fill='%230BF' %3E%3Cpath d='M0 256a256 256 0 1 1 512 0A256 256 0 1 1 0 256zM188.3 147.1c-7.6 4.2-12.3 12.3-12.3 20.9V344c0 8.7 4.7 16.7 12.3 20.9s16.8 4.1 24.3-.5l144-88c7.1-4.4 11.5-12.1 11.5-20.5s-4.4-16.1-11.5-20.5l-144-88c-7.4-4.5-16.7-4.7-24.3-.5z'/%3E%3C/svg%3E");
background-size:5rem;
}
.videoEmbed.vimeo a b {
background-image: url("data:image/svg+xml,%0A%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 70 24' fill='%230BF' %3E%3Cpath d='m 15.72,9.431 c -0.069,1.514 -1.127,3.588 -3.172,6.22 -2.114,2.749 -3.903,4.124 -5.367,4.124 -0.906,0 -1.673,-0.837 -2.3,-2.512 C 4.463,15.728 4.044,14.194 3.626,12.659 3.161,10.985 2.662,10.147 2.128,10.147 c -0.116,0 -0.524,0.245 -1.221,0.733 L 0.176,9.937 C 0.943,9.263 1.7,8.588 2.445,7.912 3.469,7.028 4.237,6.562 4.75,6.515 5.96,6.399 6.705,7.227 6.985,8.998 c 0.302,1.912 0.511,3.101 0.628,3.566 0.349,1.586 0.733,2.378 1.152,2.378 0.326,0 0.815,-0.515 1.467,-1.543 0.651,-1.029 1,-1.812 1.047,-2.349 0.093,-0.888 -0.256,-1.333 -1.047,-1.333 -0.373,0 -0.757,0.085 -1.151,0.255 0.764,-2.504 2.224,-3.721 4.38,-3.652 1.598,0.047 2.351,1.084 2.259,3.111' id='path4' /%3E%3Cpath d='m 22.281,1.918 c -0.023,0.58 -0.314,1.136 -0.874,1.669 -0.628,0.602 -1.373,0.903 -2.234,0.903 -1.327,0 -1.968,-0.579 -1.921,-1.737 0.022,-0.602 0.378,-1.182 1.064,-1.738 0.687,-0.555 1.449,-0.834 2.288,-0.834 0.489,0 0.896,0.192 1.223,0.574 0.325,0.382 0.477,0.77 0.454,1.163 z m 3.038,12.419 c -0.652,1.232 -1.548,2.349 -2.689,3.349 -1.56,1.349 -3.119,2.024 -4.679,2.024 -0.723,0 -1.275,-0.233 -1.659,-0.699 -0.384,-0.465 -0.565,-1.069 -0.541,-1.814 0.022,-0.767 0.261,-1.954 0.715,-3.56 0.454,-1.605 0.682,-2.466 0.682,-2.582 0,-0.605 -0.21,-0.908 -0.629,-0.908 -0.139,0 -0.536,0.245 -1.188,0.733 L 14.528,9.937 c 0.745,-0.674 1.49,-1.349 2.235,-2.025 1.001,-0.884 1.746,-1.35 2.236,-1.397 0.768,-0.069 1.332,0.157 1.693,0.679 0.36,0.523 0.494,1.2 0.402,2.035 -0.303,1.415 -0.629,3.212 -0.978,5.392 -0.024,0.998 0.337,1.496 1.082,1.496 0.326,0 0.908,-0.344 1.746,-1.033 0.699,-0.574 1.269,-1.114 1.712,-1.62 l 0.663,0.873' id='path6' /%3E%3Cpath d='m 47.127,14.336 c -0.652,1.233 -1.548,2.349 -2.689,3.349 -1.56,1.349 -3.12,2.024 -4.679,2.024 -1.514,0 -2.247,-0.837 -2.2,-2.513 0.022,-0.745 0.168,-1.639 0.436,-2.686 0.267,-1.048 0.413,-1.862 0.436,-2.444 0.024,-0.883 -0.245,-1.326 -0.806,-1.326 -0.607,0 -1.331,0.722 -2.172,2.165 -0.887,1.514 -1.367,2.98 -1.436,4.4 -0.05,1.002 0.05,1.77 0.293,2.305 -1.624,0.047 -2.762,-0.221 -3.411,-0.803 -0.582,-0.512 -0.848,-1.361 -0.801,-2.549 0.02,-0.745 0.136,-1.49 0.343,-2.235 0.205,-0.745 0.319,-1.408 0.342,-1.991 0.05,-0.861 -0.268,-1.292 -0.944,-1.292 -0.583,0 -1.213,0.664 -1.888,1.991 -0.676,1.326 -1.049,2.712 -1.119,4.155 -0.05,1.305 0.04,2.212 0.25,2.724 -1.598,0.047 -2.733,-0.29 -3.404,-1.01 -0.558,-0.603 -0.812,-1.52 -0.765,-2.751 0.02,-0.603 0.129,-1.445 0.321,-2.524 0.192,-1.08 0.299,-1.921 0.321,-2.525 0.05,-0.417 -0.06,-0.627 -0.314,-0.627 -0.14,0 -0.536,0.236 -1.188,0.707 L 21.215,9.937 c 0.117,-0.092 0.849,-0.768 2.2,-2.025 0.978,-0.907 1.641,-1.373 1.99,-1.396 0.606,-0.047 1.094,0.203 1.467,0.75 0.372,0.547 0.559,1.182 0.559,1.903 0,0.233 -0.02,0.454 -0.07,0.664 0.349,-0.535 0.756,-1.002 1.222,-1.398 1.071,-0.93 2.27,-1.455 3.597,-1.571 1.141,-0.093 1.955,0.174 2.445,0.803 0.395,0.512 0.581,1.246 0.558,2.2 0.163,-0.139 0.338,-0.291 0.525,-0.454 0.534,-0.628 1.058,-1.128 1.57,-1.501 0.861,-0.629 1.759,-0.978 2.689,-1.048 1.118,-0.093 1.921,0.173 2.41,0.8 0.418,0.51 0.605,1.241 0.559,2.191 -0.024,0.65 -0.181,1.595 -0.472,2.836 -0.292,1.241 -0.436,1.953 -0.436,2.139 -0.024,0.488 0.023,0.824 0.139,1.009 0.117,0.186 0.395,0.278 0.838,0.278 0.326,0 0.907,-0.344 1.746,-1.034 0.698,-0.573 1.269,-1.113 1.712,-1.619 l 0.664,0.872' id='path8' /%3E%3Cpath d='m 52.295,10.654 c 0.022,-0.625 -0.233,-0.938 -0.767,-0.938 -0.698,0 -1.407,0.481 -2.127,1.442 -0.721,0.961 -1.093,1.882 -1.116,2.762 -0.013,0 -0.013,0.151 0,0.452 1.139,-0.417 2.127,-1.053 2.964,-1.911 0.674,-0.741 1.022,-1.344 1.046,-1.807 z m 7.927,3.646 c -0.675,1.117 -2.002,2.232 -3.981,3.348 -2.467,1.418 -4.971,2.126 -7.508,2.126 -1.885,0 -3.237,-0.628 -4.051,-1.885 -0.582,-0.861 -0.861,-1.885 -0.838,-3.072 0.023,-1.885 0.862,-3.677 2.515,-5.377 1.815,-1.862 3.957,-2.794 6.425,-2.794 2.282,0 3.492,0.93 3.632,2.787 0.093,1.184 -0.559,2.404 -1.956,3.658 -1.49,1.371 -3.365,2.241 -5.622,2.612 0.418,0.581 1.046,0.871 1.885,0.871 1.676,0 3.504,-0.426 5.483,-1.279 1.42,-0.599 2.538,-1.221 3.353,-1.866 l 0.663,0.871' id='path10' /%3E%3Cpath d='m 65.755,11.828 c 0.023,-0.63 -0.064,-1.207 -0.262,-1.732 -0.198,-0.524 -0.484,-0.788 -0.855,-0.788 -1.188,0 -2.166,0.642 -2.933,1.925 -0.653,1.05 -1.003,2.17 -1.048,3.358 -0.024,0.584 0.081,1.098 0.314,1.54 0.255,0.514 0.616,0.77 1.083,0.77 1.047,0 1.944,-0.617 2.689,-1.854 0.628,-1.027 0.965,-2.1 1.012,-3.219 z m 3.946,0.132 c -0.093,2.139 -0.884,3.987 -2.374,5.544 -1.49,1.557 -3.342,2.336 -5.553,2.336 -1.839,0 -3.236,-0.593 -4.19,-1.779 -0.698,-0.883 -1.083,-1.987 -1.152,-3.311 -0.118,-2 0.604,-3.836 2.165,-5.51 1.676,-1.859 3.782,-2.789 6.32,-2.789 1.629,0 2.863,0.547 3.702,1.639 0.792,1 1.152,2.29 1.082,3.87' id='path12' /%3E%3C/svg%3E%0A");
}
.videoEmbed.youtube button {
background-image:url("data:image/svg+xml,%3Csvg width='159' height='110' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='m154 17.5c-1.82-6.73-7.07-12-13.8-13.8-9.04-3.49-96.6-5.2-122 0.1-6.73 1.82-12 7.07-13.8 13.8-4.08 17.9-4.39 56.6 0.1 74.9 1.82 6.73 7.07 12 13.8 13.8 17.9 4.12 103 4.7 122 0 6.73-1.82 12-7.07 13.8-13.8 4.35-19.5 4.66-55.8-0.1-75z' fill='%23f00'/%3E%3Cpath d='m105 55-40.8-23.4v46.8z' fill='%23fff'/%3E%3C/svg%3E%0A");
background-size:5.81rem 4rem;
}
.videoEmbed.youtube a b {
margin-left:0.25rem;
background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 507.9 113.39'%3E%3Cg fill='%23fff'%3E%3Cpath d='M64.792 80.99V32.396l42.082 24.297zm93.803-63.285a20.285 20.285 0 00-14.32-14.32C131.642 0 80.99 0 80.99 0S30.337 0 17.705 3.385a20.286 20.286 0 00-14.32 14.32C0 30.338 0 56.693 0 56.693S0 83.049 3.385 95.68A20.285 20.285 0 0017.705 110c12.632 3.386 63.285 3.386 63.285 3.386s50.652 0 63.285-3.386a20.284 20.284 0 0014.32-14.32c3.385-12.632 3.385-38.988 3.385-38.988s0-26.355-3.385-38.988m94.473 74.326c.887-2.314 1.332-6.098 1.332-11.35V58.556c0-5.097-.445-8.822-1.332-11.178-.888-2.355-2.452-3.533-4.69-3.533-2.163 0-3.69 1.178-4.577 3.533-.888 2.356-1.332 6.081-1.332 11.178V80.68c0 5.25.424 9.035 1.275 11.35.848 2.318 2.392 3.475 4.633 3.475 2.239 0 3.803-1.157 4.691-3.475zm-17.953 11.122c-3.207-2.16-5.486-5.52-6.835-10.079-1.352-4.554-2.027-10.617-2.027-18.185v-10.31c0-7.644.771-13.784 2.316-18.417 1.544-4.633 3.956-8.011 7.24-10.135 3.282-2.123 7.587-3.186 12.916-3.186 5.251 0 9.459 1.082 12.626 3.243 3.165 2.162 5.482 5.542 6.95 10.136 1.466 4.595 2.2 10.715 2.2 18.36v10.31c0 7.567-.714 13.65-2.142 18.243-1.43 4.595-3.747 7.955-6.951 10.077-3.205 2.124-7.548 3.186-13.03 3.186-5.64 0-10.06-1.082-13.263-3.243m248.053-57.981c-.81 1.005-1.352 2.646-1.621 4.923-.272 2.278-.404 5.734-.404 10.367v5.097h11.697V60.46c0-4.555-.155-8.011-.463-10.367-.309-2.355-.868-4.014-1.678-4.98-.812-.966-2.067-1.449-3.766-1.449-1.7 0-2.954.503-3.765 1.506zm-2.025 29.886v3.591c0 4.557.132 7.974.404 10.251.269 2.279.828 3.94 1.68 4.982.849 1.041 2.16 1.564 3.938 1.564 2.392 0 4.035-.927 4.923-2.781.887-1.853 1.37-4.942 1.447-9.268l13.785.812c.077.62.116 1.469.116 2.548 0 6.565-1.795 11.47-5.387 14.712-3.589 3.242-8.669 4.865-15.232 4.865-7.876 0-13.398-2.47-16.564-7.414-3.168-4.94-4.75-12.586-4.75-22.935V63.589c0-10.657 1.641-18.436 4.924-23.342 3.281-4.903 8.9-7.355 16.854-7.355 5.482 0 9.691 1.004 12.626 3.012 2.933 2.01 5 5.137 6.197 9.383 1.197 4.247 1.796 10.117 1.796 17.607v12.163h-26.757m-284.953-1.33l-18.187-65.68h15.869l6.37 29.77c1.623 7.339 2.82 13.594 3.591 18.766h.464c.54-3.706 1.738-9.922 3.591-18.65l6.603-29.886h15.869l-18.417 65.68v31.51h-15.754v-31.51M322.115 34.23v71.007h-12.511l-1.39-8.688h-.347c-3.399 6.564-8.496 9.845-15.291 9.845-4.71 0-8.185-1.543-10.425-4.633-2.24-3.087-3.359-7.915-3.359-14.48V34.23h15.985v52.126c0 3.168.348 5.426 1.043 6.776.695 1.353 1.853 2.027 3.475 2.027 1.39 0 2.722-.423 3.996-1.275 1.274-.849 2.22-1.928 2.838-3.241V34.229h15.986m81.995.001v71.007h-12.511l-1.391-8.688h-.345c-3.402 6.564-8.498 9.845-15.292 9.845-4.711 0-8.186-1.543-10.426-4.633-2.24-3.087-3.358-7.915-3.358-14.48V34.23h15.985v52.126c0 3.168.347 5.426 1.041 6.776.696 1.353 1.855 2.027 3.476 2.027 1.391 0 2.723-.423 3.996-1.275 1.275-.849 2.22-1.928 2.839-3.241V34.229h15.985'%3E%3C/path%3E%3Cpath d='M365.552 20.908h-15.87v84.329h-15.637v-84.33h-15.869V8.05h47.376v12.858m76.811 53.636c0 5.174-.215 9.229-.639 12.162-.424 2.937-1.139 5.021-2.143 6.255-1.004 1.236-2.357 1.854-4.053 1.854a7.404 7.404 0 01-3.65-.927c-1.12-.618-2.026-1.544-2.722-2.78V50.796c.54-1.93 1.467-3.513 2.78-4.749 1.313-1.234 2.74-1.853 4.285-1.853 1.623 0 2.876.637 3.766 1.91.886 1.275 1.505 3.418 1.853 6.43.348 3.011.523 7.297.523 12.857zm14.652-28.964c-.967-4.478-2.531-7.721-4.692-9.73-2.163-2.007-5.136-3.011-8.919-3.011-2.935 0-5.676.83-8.224 2.49a16.926 16.926 0 00-5.908 6.545h-.117l.001-37.416h-15.405v100.777h13.204l1.622-6.717h.347c1.235 2.393 3.088 4.285 5.56 5.675 2.47 1.39 5.213 2.085 8.225 2.085 5.404 0 9.382-2.491 11.931-7.471 2.548-4.982 3.823-12.76 3.823-23.341V64.23c0-7.953-.484-14.17-1.448-18.65'%3E%3C/path%3E%3C/g%3E%3C/svg%3E");
}
{ // video facades
const
sources = {
"vimeo" : {
allow : "autoplay; fullscreen; picture-in-picture",
path : (url) => `https://player.vimeo.com/video${url.pathname}?autoplay=1`
}, // vimeo
"youtube" : {
allow : "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
path : (url) => "https://www.youtube.com/embed" + (
url.pathname === "/watch" ?
"/" + url.searchParams.get("v") :
url.pathname
) + "?autoplay=1"
} // youtube
}, // sources
domains = {
"vimeo.com" : "vimeo",
"youtu.be" : "youtube",
"www.youtube.com" : "youtube"
}, // domains
make = (parent, tagName, ...attr) => {
return parent.appendChild(
Object.assign(
document.createElement(tagName),
...attr
)
);
}, // make
buttonAttr = {
onclick : (e) => {
const iframe = make(e.currentTarget.parentNode, "iframe", {
allow : sources[e.currentTarget.dataset.videoHost].allow,
allowfullscreen : true,
allowtransparency : true,
frameborder : "0",
src : e.currentTarget.value
} );
while (iframe.previousSibling) iframe.previousSibling.remove();
}, // onclick
type : "button"
}; // buttonAttr
for (const a of document.querySelectorAll(".videoEmbed > a")) {
const
url = new URL(a.href),
host = domains[url.hostname],
source = sources[host];
if (source) make(a.parentNode, "button", buttonAttr, {
textContent : a.previousElementSibling.textContent,
value : source.path(url)
}).dataset.videoHost = host;
else console.warn(`video source "${url.hostname}" not supported`);
}
} // video facades
Also see: Tab Triggers