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="notice"></div>

<div class="article-block js-bgimg" style="background-image: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/9186/sky-square.jpg')" data-bgimg="https://s3-us-west-2.amazonaws.com/s.cdpn.io/9186/sky-square.jpg" data-bgimg-retina="https://s3-us-west-2.amazonaws.com/s.cdpn.io/9186/sky-square@2x.jpg" data-bgimg-large="https://s3-us-west-2.amazonaws.com/s.cdpn.io/9186/sky.jpg" data-bgimg-large-retina="https://s3-us-west-2.amazonaws.com/s.cdpn.io/9186/sky@2x.jpg">
  <div class="article-block__body">
    <h1>Blue Heaven on Earth</h1>
              body { padding: 2em; }

h1 {
  color: white;
  margin: 0;

.notice {
  background: gray;
  margin-bottom: 2em;
  padding: 0.5em;
  color: white;
  border-radius: 5px;

.article-block {
  position: relative;
  background-size: cover;
  background-repeat: no-repeat;
  background-position: center;
  padding: 2em;
  min-height: 320px;
  border-radius: 1em;
  overflow: hidden;

.article-block__body {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1.5em;
  background: rgba(0,0,0,.3);
 * enquire.js v2.1.2 - Awesome Media Queries in JavaScript
 * Copyright (c) 2014 Nick Williams - http://wicky.nillia.ms/enquire.js
 * License: MIT (https://www.opensource.org/licenses/mit-license.php)

!function(a,b,c){var d=window.matchMedia;"undefined"!=typeof module&&module.exports?module.exports=c(d):"function"==typeof define&&define.amd?define(function(){return b[a]=c(d)}):b[a]=c(d)}("enquire",this,function(a){"use strict";function b(a,b){var c,d=0,e=a.length;for(d;e>d&&(c=b(a[d],d),c!==!1);d++);}function c(a){return"[object Array]"===Object.prototype.toString.apply(a)}function d(a){return"function"==typeof a}function e(a){this.options=a,!a.deferSetup&&this.setup()}function f(b,c){this.query=b,this.isUnconditional=c,this.handlers=[],this.mql=a(b);var d=this;this.listener=function(a){d.mql=a,d.assess()},this.mql.addListener(this.listener)}function g(){if(!a)throw new Error("matchMedia not present, legacy browsers require a polyfill");this.queries={},this.browserIsIncapable=!a("only all").matches}return e.prototype={setup:function(){this.options.setup&&this.options.setup(),this.initialised=!0},on:function(){!this.initialised&&this.setup(),this.options.match&&this.options.match()},off:function(){this.options.unmatch&&this.options.unmatch()},destroy:function(){this.options.destroy?this.options.destroy():this.off()},equals:function(a){return this.options===a||this.options.match===a}},f.prototype={addHandler:function(a){var b=new e(a);this.handlers.push(b),this.matches()&&b.on()},removeHandler:function(a){var c=this.handlers;b(c,function(b,d){return b.equals(a)?(b.destroy(),!c.splice(d,1)):void 0})},matches:function(){return this.mql.matches||this.isUnconditional},clear:function(){b(this.handlers,function(a){a.destroy()}),this.mql.removeListener(this.listener),this.handlers.length=0},assess:function(){var a=this.matches()?"on":"off";b(this.handlers,function(b){b[a]()})}},g.prototype={register:function(a,e,g){var h=this.queries,i=g&&this.browserIsIncapable;return h[a]||(h[a]=new f(a,i)),d(e)&&(e={match:e}),c(e)||(e=[e]),b(e,function(b){d(b)&&(b={match:b}),h[a].addHandler(b)}),this},unregister:function(a,b){var c=this.queries[a];return c&&(b?c.removeHandler(b):(c.clear(),delete this.queries[a])),this}},new g});

// begin custom function

function img() {
  $('.js-bgimg').each(function() {
    var bgImg = $(this);
    var imgStandard = bgImg.data('bgimg');
    var imgRetina = bgImg.data('bgimg-retina');
    var imgLarge = bgImg.data('bgimg-large');
    var imgLargeRetina = bgImg.data('bgimg-large-retina');
    // simple function to replace background image
    function replaceImg(el, replacementImg) {
      el.attr('style', 'background-image: url("'+ replacementImg +'")');
    // where are we? I set this up so you can what state is active in enquire.
    $('.notice').text('No enquire states, yet.');
      // when min-width: 62em registers, run this code
      .register("screen and (min-width: 62em)", {
        match : function() {
          // update our notice, it matches
          // now we just update the image for our large image
          replaceImg(bgImg, imgLarge);
        // if the screen gets smaller, it'll "unmatch" from our media query
        unmatch : function() {
          // update the notice! no longer matching.
          // let's use our standard square image
          replaceImg(bgImg, imgStandard);
        // we need to test for retina on setup
        setup : function() {
          // we can use matchmedia to test if we have retina or not.
          // since the standard image is pre-loaded in mark-up, we only need to test for retina
          if (matchMedia('screen and (-webkit-min-device-pixel-ratio: 2), screen and (min-resolution: 192dpi)').matches) {
            // update our notice
            $('.notice').text('setup officially official');
            // update our image for retina!
            replaceImg(bgImg, imgRetina);  
      // okay, now we're testing our screen width AND for retina images.
      .register("screen and (min-width: 62em) and (-webkit-min-device-pixel-ratio: 2), screen and (min-width: 62em) and (min-resolution: 192dpi)", {
        match : function() {
          // let's update the notice
          $('.notice').text('retina match');
          // we have retina and a large screen, let's use the large retina graphic
          replaceImg(bgImg, imgLargeRetina);
        unmatch : function() {
          // update the notice
          $('.notice').text('retina unmatch');
          // no longer in a wide screen, so update the image to be our square retina graphic
          replaceImg(bgImg, imgRetina);

🕑 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 ..................