css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

    <h1>Half of U.S. young adults want to &#8216;fast&#8212;forward&#8217; by 10 years, out of fear.</h1>
    <p>By Ben Norman, 10/12/2016</p>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum pulvinar sit amet turpis sit amet gravida. Duis sit amet pulvinar turpis. Proin tempor ex in enim faucibus pellentesque nec at neque. Sed eget justo malesuada nisl laoreet rutrum. Praesent suscipit euismod nunc vel imperdiet. Mauris ac odio metus.</p>
    <p>Etiam tempor ornare mattis. Pellentesque fringilla fringilla eros quis dignissim. Morbi tristique ultrices diam eget hendrerit.</p>
    <p>Nullam non magna pharetra eros iaculis euismod. Ut at libero ac leo mattis mollis. Praesent sodales maximus orci ac fringilla. Morbi dolor augue, condimentum cursus neque ut, vulputate molestie metus. Curabitur vestibulum quam eget faucibus sollicitudin. Aliquam a ligula id ante cursus semper imperdiet in tortor.</p>
    <p>Curabitur molestie lorem a nunc posuere cursus. Curabitur posuere venenatis ligula, vel dignissim turpis vehicula in. Sed at pretium est.</p>
      <img src="https://leibrug.pl/img/posts/enhance-your-media-with-canvas-over-technique/canvas-over-concerned-man.jpg">
      <canvas id="canvas"></canvas>
      <figcaption>American young adults face many doubts at their early&#8212;twenties.</figcaption>
    <p>Vestibulum scelerisque at diam nec commodo. Mauris sodales leo ac tincidunt blandit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Pellentesque diam odio, pretium ornare justo a, euismod tempor sem. Nunc nec sagittis nibh, ac bibendum odio. Nulla facilisi.</p>
    <p>Vestibulum commodo viverra lacus, nec ultrices lacus accumsan eget. In egestas porttitor diam a varius. Duis porta vel sem non imperdiet. Fusce vel risus fermentum, tempor est molestie, egestas nunc. Nulla ac urna sit amet tellus porta interdum. Aliquam lacinia felis vitae finibus sollicitudin.</p>
    <a href="https://www.flickr.com/photos/lentzstudios/4361222379/">"nothing like a profile"</a> by <a href="https://www.flickr.com/photos/lentzstudios/">Teeejayy</a> / <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC BY-SA</a>
figure {
  margin: 0;
article {
  max-width: 60em;
  margin: 0 auto;
  padding: 2em;
footer {
  font-family: serif;
  font-size: 18px;
main {
  line-height: 1.5;
  -moz-columns: 2;
  columns: 2;
  -moz-column-gap: 2em;
  column-gap: 2em;
h1 {
  font-size: 36px;
  margin: 0 0 .25em;
header p {
  font-size: 24px;
figcaption {
  margin: 0 0 1em;
figure {
  position: relative;
img {
  width: 100%;
  height: auto;
canvas {
  position: absolute;
  top: 0;
  left: 0;
footer {
  border-top: 1px #000 solid;
  margin-top: 1em;
  padding-top: 2em;
              // Config
var cfg = {
  textStyle: '14px sans-serif',
  textColor: '#fff',
  lineSpacing: 30,
  positionX: 30,
  positionY: 40,
  moveDuration: 500,
  moveRepeat: 1000

// Doubts list
var doubts = [
  'Rent or own a house?',
  'How will I pay my college loan?',
  'Should I move for the better job?',
  'Will she support me?',
  'How can I help my parents?'

// Refs
var canvas = document.getElementById('canvas');
var image = canvas.previousElementSibling;
var ctx = canvas.getContext('2d');

// Gradient mask
var maskHeight = cfg.positionY + doubts.length * cfg.lineSpacing + parseInt(cfg.textStyle);
var mask = ctx.createLinearGradient(0, 0, 0, maskHeight);
mask.addColorStop(0.15, '#000');
mask.addColorStop(0.45, 'transparent');
mask.addColorStop(0.55, 'transparent');
mask.addColorStop(0.85, '#000');

function drawMask() {
  ctx.globalCompositeOperation = 'destination-out';
  ctx.fillStyle = mask;
  ctx.fillRect(0, 0, canvas.width, maskHeight);

  // Reset
  ctx.globalCompositeOperation = 'source-over';
  ctx.fillStyle = cfg.textColor;

// Loop
var lastMoveTimeStamp = 0;

function draw(timeStamp) {
  var delta = timeStamp - lastMoveTimeStamp;

  // First run
  if (lastMoveTimeStamp === 0) {
    lastMoveTimeStamp = timeStamp;

  // Calculate text offset in this frame
  var textOffsetY = 0;
  if (delta >= cfg.moveRepeat) {
    textOffsetY = -Math.min((delta - cfg.moveRepeat) / cfg.moveDuration * cfg.lineSpacing, cfg.lineSpacing);

  // Draw all
  ctx.clearRect(0, 0, canvas.width, maskHeight);
  for (var i = 0; i < doubts.length; i++) {
    ctx.fillText(doubts[i], cfg.positionX, i * cfg.lineSpacing + cfg.positionY + textOffsetY);

  // End of move
  if (delta >= cfg.moveRepeat + cfg.moveDuration) {
    lastMoveTimeStamp = timeStamp;


// Init
image.addEventListener('load', function() {
  canvas.width = image.width;
  canvas.height = image.height;
  ctx.font = cfg.textStyle;
  ctx.fillStyle = cfg.textColor;
}, false);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................