Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

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.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1 style="background-image: url(https://images.unsplash.com/photo-1507296767064-5f866cd8aceb?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=68f327d797f396aeb0722fa4b6abdc70);" class="text-clip something">AIAI</h1>


<h2 style="background-image: url(https://images.unsplash.com/photo-1536502561052-8fcc215c8370?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=d453ea9c92a40dc60f7c1a6d7a9f19b9);" class="text-clip">30</h2>

              
            
!

CSS

              
                body {
  background: #112634;
}
.text-clip {
  display: inline;
  font-weight: 700;
  padding: 0;
  margin: 0;
  line-height: 1;
  font-size:350px;
  height: 350px;
  width: auto;
  line-height: 1;
  background-color: transparent;
  background-repeat: no-repeat; 
  -webkit-text-fill-color: transparent; 
  -webkit-background-clip: text; 
  background-size:cover;
  
}


              
            
!

JS

              
                function runClip() { 
  $('.text-clip').each(function(i){
    var $svgEle = $(this);
    var hgt = $svgEle.height(); //height of text element
    var wdth = $svgEle.width(); //width of text element
    var bgImgH; //will be height of background-image
    var bgImgW; //will be width of background-image
    var pattW; //calculated width of pattern image
    var pattH; //calculated height of pattern image
    var value = $svgEle.html(); //gets text to push into svg
    var pattID = 'patternIMG' + i; //sets id for pattern using index to make it unique
    var classes = $svgEle.attr('class'); //grabs all classes of text element
    var aiPattURL = $svgEle.css('background-image').slice(4, -1).replace(/"/g, ""); //gets background-image url 

    var getImage = function(url) {
   
      var dfd = new $.Deferred();

      if (url) {
          var image = new Image();
          image.onload = dfd.resolve;
          image.onerror = dfd.reject;
          image.src = url;
        
      } else {
          dfd.reject();
      }

      return dfd.then(function() {
          return { width: this.width, height: this.height };
      });
    };

    getImage(aiPattURL)
    .then(function(size) {
      bgImgW = size.width;
      bgImgH = size.height;
      //Checks aspect ratio of text vs background-image then sets pattern image size vars.
      if( hgt/wdth > bgImgH/bgImgW ){
        pattH = hgt;
        pattW = hgt * bgImgW / bgImgH;
      } else {
        pattW = wdth;
        pattH = wdth * bgImgH / bgImgW;
      }
      //Prints svg where text element used to be.
      $svgEle.replaceWith('<svg viewBox="0 0 ' + wdth + ' ' + hgt + '" height="'+ hgt +'" width="' + wdth + '"><pattern patternUnits="userSpaceOnUse" height="'+ pattH +'" width="' + pattW + '" id="'+ pattID +'" ><image  x="0" y="0" height="'+ pattH +'" width="' + pattW + '" xlink:href="' + aiPattURL + '"></image></pattern><text x="0" y="77%" class="'+ classes +'" fill="url(#' + pattID + ')" >' + value + '</text></svg>')
    })
    .fail(function() {
      console.log('CSS background-image failed to load, sorry...');
    });  
  })
}
try {
  // Checks if -webkit-background-clip: text is supported.
  if ( !CSS.supports("-webkit-background-clip", "text") ){
    runClip()
  }
} catch(e){
  // Callback catch for older browsers that don't understand CSS.suppports().
  runClip();
}

//uncomment to test:
// runClip()

              
            
!
999px

Console