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.

              <div class="page-head--masthead">
              // Blurground:
// Create a blurry background image 
// using radial gradients as "pixel 
// blobs". Inspired by Harry Roberts'
// blog post: 
// https://csswizardry.com/2016/10/improving-perceived-performance-with-multiple-background-images
// WARNING: This is ridiculous

// First you need to reduce your source 
// image to the desired size, using 
// Photoshop or similar. In this example 
// I've reduced this image: 
// https://csswizardry.com/img/css/masthead-large.jpg
// to 8x4 pixels. Use Photoshop's 
// inkdropper tool to record the colour 
// of each pixel, and list them in a
// a Sass list, like this:

$myColours: #9EA0A3, #9C9A97, #362F29, #15100D, #271E17, #241C17, #040201, #1C1C1C, #A9ABAC, #999999, #190E03, #000000, #6A4D44, #533C37, #000000, #141111, #AC9479, #746454, #0A0300, #3B3134, #715A60, #5C453E, #15100C, #0D0D0D, #A37A52, #49301A, #0D0D0D, #493B3A, #584D51, #624638, #1A0C06, #2A2A2C;

// I guess this bit could be automated
// using Node or ImageMagick or 
// something? I'll leave that job to
// someone smarter than me...

// Blurground will turn each pixel into 
// a radial gradient, or blob. So in 
// this example we'll end up with an 
// 8x4 grid of blobs.

// $rowLength = number of blobs in width
// $columnLength = num. blobs in height
// $colours = your Sass list of colours
@function blurground($rowLength, $columnLength, $colours) {
  // Determines the size of each grid square
  $blobWidth: 100%/$rowLength;
  $blobHeight: 100%/$columnLength;
  // Centre-align each blob within its grid square
  $xOffset: $blobWidth/2;
  $yOffset: $blobHeight/2;
  // Size determines how much the blobs 
  // overlap: if size==width, no overlap
  $xSize: $blobWidth*2;
  $ySize: $blobHeight*2;
  // An empty string which will contain our CSS
  $result: "";
  // This code loops through each colour
  // in the list, creating a radial 
  // gradient (or blob) for each. We
  // know what number blob we're on, and
  // the size of our grid, so calculatin
  // calculating each blob's x & y
  // co-ordinates is just a math problem
  @for $currentBlob from 1 through length($colours) {
    // What row are we on? 
    $row: ceil($currentBlob/$rowLength);
    $const: $row - 1;
    $xPosition: (($currentBlob - ($rowLength * $const)) * $blobWidth) - $xOffset;
    $yPosition: ($blobHeight * $row) - $yOffset;
    $string: "radial-gradient(ellipse #{$xSize} #{$ySize} at #{$xPosition} #{$yPosition}, #{rgba(nth($colours,$currentBlob),1)}, #{rgba(nth($colours,$currentBlob),0)})";
    $separator: "";
    @if ($currentBlob != 1) {
      $separator: ",";
    $result: $result + $separator + $string;
  @return unquote($result);

// 3. USAGE
// That's it! Here's how you'd use 
// the function:
.page-head--masthead {
  background-image: blurground(8,4,$myColours);
  height: 426px;

// Thanks for reading!

// This is just a thought experiment;
// I would never suggest anyone use
// this code in production. The CSS
// it produces could potentially be 
// much heavier than the source image, 
// therefore entirely missing the point 
// of Harry's initial blog post. It was
// fun to mess around with though :D
🕑 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 ..................