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.
<div class="note">
Tilt the head to vary the ascendants of the word "village"
</div>
<article>
<h1>The hitchhiker's Guide to the Galaxy</h1>
<h2>Chapter 1</h2>
<p>The house stood on a slight rise just on the edge of the <span style="color: red;">village</span>. It stood on its own and looked out over a broad spread of West Country farmland. Not a remarkable house by any means—it was about thirty years old, squattish, squarish, made of brick, and had four windows set in the front of a size and proportion which more or less exactly failed to please the eye. </p>
<p>The only person for whom the house was in any way special was Arthur Dent, and that was only because it happened to be the one he lived in. He had lived in it for about three years, ever since he had moved out of London because it made him nervous and irritable. He was about thirty as well, tall, dark-haired and never quite at ease with himself. The thing that used to worry him most was the fact that people always used to ask him what he was looking so worried about. He worked in local radio which he always used to tell his friends was a lot more interesting than they probably thought. It was, too—most of his friends worked in advertising.</p>
<p>On Wednesday night it had rained very heavily, the lane was wet and muddy, but the Thursday morning sun was bright and clear as it shone on Arthur Dent’s house for what was to be the last time.</p>
<p>It hadn’t properly registered yet with Arthur that the council wanted to knock it down and build a bypass instead.</p>
</article>
<div class="dev">
<video></video>
<canvas></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/facemesh"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/7.2.0/math.min.js"></script>
@font-face {
src: url('https://cors-anywhere.herokuapp.com/https://v-fonts.com/assets/fonts/AmstelvarAlpha-VF.woff2');
font-family:'Amstelvar';
font-style: normal;
}
:root {
--angle: 0;
}
html, body {
margin: 0;
padding: 0;
font-family: 'Amstelvar', serif;
}
article {
padding: 1em;
width: 60ch;
max-width: 100%;
font-size: 1.5em;
line-height: calc(1ex / .32);
--min-ascender: 750;
--max-ascender: 850;
--ascender: max(var(--min-ascender), calc(var(--min-ascender) + (var(--angle) * (var(--max-ascender) - var(--min-ascender)))));
--min-descender: 250;
--max-descender: 350;
--descender: max(var(--min-descender), calc(var(--min-descender) + (-1 * var(--angle) * (var(--max-descender) - var(--min-descender)))));
font-variation-settings: 'YTAS' var(--ascender), 'YTDE' var(--descender);
}
article > *:first-child {
margin-top: 0;
}
article > *:last-child {
margin-bottom: 0;
}
article p {
margin: 0 0 0.75em 0;
}
.dev {
position: fixed;
bottom: 1em;
right: 1em;
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
.dev video {
display: block;
width: 320px;
max-width: 50vw;
height: auto;
}
.dev canvas {
position: absolute;
top: 0;
left: 0;
display: block;
width: 100%;
height: 100%;
}
.note {
padding: 1em;
font-family: sans-serif;
font-size: 1.5em;
background: #e1f9fd;
}
(async () => {
// get the video
const video = document.querySelector('video');
// setup facemesh
const model = await facemesh.load({
backend: 'wasm',
maxFaces: 1,
});
async function detectFaces() {
const faces = await model.estimateFaces(video);
// dev stuff
renderPrediction(video, faces);
if (faces.length === 0) {
// is somebody out there?
return requestAnimationFrame(detectFaces);
}
const [face] = faces;
let mesh = math.matrix(face.scaledMesh);
let leftEyeCoords = math.squeeze(math.row(mesh, 33)).toArray();
let rightEyeCoords = math.squeeze(math.row(mesh, 263)).toArray();
let midPointCoords = [
(leftEyeCoords[0] + rightEyeCoords[0]) / 2,
leftEyeCoords[1],
leftEyeCoords[2],
];
let chinCoords = math.squeeze(math.row(mesh, 152)).toArray();
let rx = math.subtract(leftEyeCoords, rightEyeCoords);
rx = math.divide(rx, math.norm(rx));
let ry = math.subtract(midPointCoords, chinCoords);
ry = math.divide(ry, math.norm(ry));
let rz = math.cross(rx, ry);
let rotationMatrix = math.matrix([rx, ry, rz]).toArray();
let sy = Math.sqrt(Math.pow(rotationMatrix[0][0], 2) + Math.pow(rotationMatrix[1][0], 2));
let angle;
if (sy < 0.000001) {
angle = Math.atan2(rotationMatrix[1][2], rotationMatrix[1][1]);
} else {
angle = Math.atan2(rotationMatrix[2][1], rotationMatrix[2][2]);
}
document.documentElement.style.setProperty('--angle', Math.round(angle * 10) / 10);
// recursively detect faces
requestAnimationFrame(detectFaces);
}
// enable autoplay
video.setAttribute('autoplay', '');
video.setAttribute('muted', '');
video.setAttribute('playsinline', '');
// start face detection when ready
video.addEventListener('canplaythrough', detectFaces);
// stream the camera
video.srcObject = await navigator.mediaDevices.getUserMedia({
audio: false,
video: {
facingMode: 'user',
},
});
// let’s go!
video.play();
})();
async function renderPrediction(video, predictions) {
const canvas = document.querySelector('canvas');
if (canvas.width !== video.videoWidth) {
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
}
const ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, canvas.width, canvas.height);
predictions.forEach(prediction => {
const keypoints = prediction.scaledMesh;
for (let i = 0; i < keypoints.length; i++) {
const x = keypoints[i][0];
const y = keypoints[i][1];
ctx.fillStyle = '#32EEDB';
ctx.strokeStyle = '#32EEDB';
ctx.beginPath();
ctx.arc(x, y, 1 /* radius */ , 0, 2 * Math.PI);
ctx.fill();
}
});
}
Also see: Tab Triggers