Pen Settings



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


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


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.


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.


<p>The picture of the eagle scales up and down depending on the device dimenisons. This will keep sizing, dimensions and spacing of the elements of the game relatively consistent to every device.</p>


body {
  height: 100%;
  padding: 0;
  margin: 0;
  overflow: hidden;

canvas {
  width: 100%;
  height: 100%;
  background: #999999;
  z-index: 2;

p {
  position: absolute;
  bottom: 0;
  padding: 1em;



                const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");

let img = new Image();
img.src =

window.onresize = resize;

img.onload = () => {

function render() {
  ctx.drawImage(img, $(5), $(5), $(30), $(30));

function resize() {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;

// function for percentages

The math is simple. n percent of the width is divided by f, and added to n percent of the height divided by f. f can be adjusted to control the size of the units.

  This gives us our "viewport units", and makes is to that the sizing of the game content can adapt slightly depending on how large the viewport is, while maintaining consistent widths, heights and distances between renderings.

function $(n, f = 2) {
  return ((n / 100) * window.innerWidth) / f + (n / 100) * window.innerHeight;