Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

Auto Save

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>device pixel ratio: <output></output></h1>

<p>
  With CSS, 
  we can <code>zoom</code> or <code>scale</code> specific elements
  (see the CSS code) —
  but it won't change the result of our media queries,
  which measure the resolution of the entire viewport.
  However, if we zoom the entire page using browser controls,
  we will see the media resolution changing.
  Different monitors may also give different DPR results.
</p>
              
            
!

CSS

              
                body {
/* 
  Zoom changes the size of a CSS pixel **before rendering**,
  so the page has fewer/larger pixels available for layout.
  Note that the text wraps, so things still fit on the page.
*/
/*   zoom: 2; */
  
/* 
  Scale magnifies the rendered output **after rendering**,
  so it has no impact on the layout of the overall page.
  Note that the entire element will overflow the page.
*/
/*   scale: 2; */
  
  border: thick var(--dpr, dotted maroon);
  @media (resolution >= 1x) { --dpr: dashed teal; }
  @media (resolution >= 2x) { --dpr: solid mediumvioletred; }
}





@layer reset, base;

@layer base {
  body {    
    --text-small: clamp(0.938rem, 0.824rem + 0.568cqi, 1.25rem);
    --text-normal: clamp(1.25rem, 1.023rem + 1.136cqi, 1.875rem);
    --text-large: clamp(1.35rem, 0.818rem + 2.659cqi, 2.813rem);
    --text-xlarge: clamp(1.7rem, 0.784rem + 4.58cqi, 4.219rem);
    --gap: clamp(12px, 0rem + 3.75cqi, 24px);
    font-size: var(--text-normal);
    padding: var(--gap);
    margin: var(--gap);
    transform-origin: 0 0;
  }
}

@layer reset {
  * { box-sizing: border-box; }
  html { block-size: 100%; }
  h1 { margin: unset; }
  
  img,
  svg {
    display: block;
    max-inline-size: 100%;
  }
  
  picture { display: contents; }
  
  input,
  button,
  textarea,
  select {
    font: inherit;
  }
}

              
            
!

JS

              
                // borrowed from MDN:
// https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio#monitoring_screen_resolution_or_zoom_level_changes

let remove = null;
const output = document.querySelector("output");

const updatePixelRatio = () => {
  if (remove != null) {
    remove();
  }
  const mqString = `(resolution: ${window.devicePixelRatio}dppx)`;
  const media = matchMedia(mqString);
  media.addEventListener("change", updatePixelRatio);
  
  remove = () => {
    media.removeEventListener("change", updatePixelRatio);
  };

  output.textContent = `${window.devicePixelRatio}`;
};

updatePixelRatio();

              
            
!
999px

Console