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>Testing <code>@function</code></h1>
<p>
  This feature is experimental,
  and <strong class='warning'>is not</strong> 
  <strong>supported</strong> in your current browser.
  <span class='warning'>
    Try Chrome Canary
    with the
    <em>Experimental Web Platform Features</em> flag enabled.
  </span>
</p>
<ul>
  <li>
    <code>--to-white(--color, --step)</code>
    & <code>--to-black(--color, --step)</code>
    move a color towards <code>white</code> or <code>black</code>
    by a given number of steps.
    There are <code>10</code> steps available by default,
    but that can be changed by defining <code>--color-steps</code>.
    The default <code>--step</code> is half of the total steps available.
  </li>
  <li>
    <code>--media-scheme()</code> returns 
    the user's preferred color-scheme.
  </li>
  <li>
    <code>--canvas(--color, --step)</code> & 
    <code>--text(--color, --step)</code>
    adjust a color towards <code>Canvas</code> or <code>CanvasText</code>.
    The default <code>--step</code> is the one
    nearest to <code>90%</code>.
  </li>
  <li>
    <code>--transparent(--color, --alpha)</code>
    returns a color with the alpha value adjusted.
  </li>
</ul>
              
            
!

CSS

              
                /* only apply a value in browsers that support functions */
@function --if-support(--value) { result: var(--value); }

.warning {
  display: --if-support(none);
}

html {
  --color-steps: 10;
  
  /* a warning for browsers without support */
  background: repeating-linear-gradient(-45deg, yellow 0 1em, black 1em 2em);
  
  /* We can also use @suports */
  /* this is needed because we're also using variables */
  /* see: https://codepen.io/miriamsuzanne/pen/WbNXbVP */
  @supports (color: --fn()) {    
    background: linear-gradient(
      to right, 
      --to-black(MediumVioletRed, var(--color-steps)) 20%,
      --to-black(MediumVioletRed) 20% 40%,
      MediumVioletRed 40% 60%,
      --to-white(MediumVioletRed) 60% 80%,
      --to-white(MediumVioletRed, var(--color-steps)) 80%
    );
  }

  color-scheme: var(--color-scheme, --media-scheme());
}

body {  
  /* we can also provide inline fallbacks */
  background: Canvas;
  color: CanvasText;
  
  /* these will be ignored in other browsers */
  background: --transparent(--canvas(teal), 85%);
  color: --text(teal);
}

@function --media-scheme() {
  result: light;
  @media (prefers-color-scheme: dark) { result: dark; }
}

@function --transparent(
  --color <color>, 
  --alpha: 0.5
) {
  result: oklch(from var(--color) l c h / var(--alpha, 0.5));
}

@function --to-white(
  --color <color>, 
  --step: round(var(--color-steps) / 2)
) {
  result: color-mix(in oklch,
    var(--color),
    white --color-step-mix(var(--step))
  );
}

@function --to-black(
  --color <color>, 
  --step: round(var(--color-steps) / 2)
) {
  result: color-mix(in oklch,
    var(--color),
    black --color-step-mix(var(--step))
  );
}

@function --canvas(
  --color <color>, 
  --step: round(var(--color-steps) * 0.9)
) {
  result: color-mix(in oklch,
    var(--color),
    Canvas --color-step-mix(var(--step))
  );
}

@function --text(
  --color <color>, 
  --step: round(var(--color-steps) * 0.9)
) {
  result: color-mix(in oklch,
    var(--color),
    CanvasText --color-step-mix(var(--step))
  );
}

@function --color-step-mix(--step) {
  --step-value: calc(95% / var(--color-steps));
  result: calc(var(--step, 1) * var(--step-value));
}



@layer reset, props, base;

@layer base {
  html {
    font-family: var(--serif);
    block-size: 100%;
    display: grid;
    padding: 1em;
    place-content: safe center;
  }
  
  [color-scheme=dark] { --color-scheme: dark; }
  [color-scheme=light] { --color-scheme: light; }

  body {    
    border: medium solid teal;
    font-size: var(--text-normal);
    padding: var(--gap);
  }
    
  [demo-style] {
    border-block: thin dashed;
    display: block;
    font-family: monospace;
    margin-block: 0.5lh;
    overflow: auto;
    padding-block: 0.5lh;
    white-space: pre;
  }

  code:not(pre *) {
    background: linear-gradient(
      -80deg,
      transparent 0.5ch,
      var(--pink-bg) 0.5ch calc(100% - 0.5ch),
      transparent calc(100% - 0.5ch)
    ) no-repeat 0 1ex;
    text-shadow: 2px 2px 0 Canvas;
  }
}

@layer props {
  html {
    /* from https://modernfontstacks.com/ */
    /* old style, industrial, slab */
    --serif: 'Iowan Old Style', 'Palatino Linotype', 'URW Palladio L', P052, serif;
    --sans: Bahnschrift, 'DIN Alternate', 'Franklin Gothic Medium', 'Nimbus Sans Narrow', sans-serif-condensed, sans-serif;
    --slab: Rockwell, 'Rockwell Nova', 'Roboto Slab', 'DejaVu Serif', 'Sitka Small', serif;
  }
  
  body {
    --text-normal: clamp(1em, 0.9em + 0.5vi, 2em);
    --gap: clamp(2cqi, 0.5lh, 5cqi);
  }
}

@layer reset {
  * { box-sizing: border-box; }
  html { block-size: 100%; }
  body { margin: unset; }
  
  h1, h2, h3, h4, h5, h6 {
    text-wrap: balance;
  }
  
  p, li {
    text-wrap: pretty;
  }
  
  picture { display: contents; }
  img { display: block; }

  img,
  svg {
    max-inline-size: 100%;
    block-size: auto;
  }
    
  input,
  button,
  textarea,
  select {
    font: inherit;
  }
}

              
            
!

JS

              
                
              
            
!
999px

Console