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

              
                <style id="pre-target"></style>

<h1>view transitions</h1>

<pre contentEditable><code>h1 {
  margin-block-end: 2rem;
}</code>
</pre>
              
            
!

CSS

              
                @font-face {
  font-family: 'Monaspace';
  src: 
    url('https://assets.codepen.io/2585/MonaspaceKrypton-SyntaxHighlighter-Regular.woff2') 
    format('woff2')
  ;
}

@layer demo {
  pre {
    view-transition-name: demo-pre;
  }
  
  h1 {
    view-transition-name: demo;
  }
}








/* light syntax theme */
@font-palette-values --kung-fury {
  font-family: "Monaspace";
  override-colors:
    0 hsl(225 100% 40%), /* curlies and tags */
    1 hsl(250 100% 80%), /* ? */
    2 hsl(225 100% 40%), /* function */
    3 hsl(225 100% 40%), /* ? */
    4 hsl(270 50% 40%),  /* () */
    5 hsl(210 40% 2%),   /* property name */ 
    6 hsl(210 10% 30%),  /* ? */
    7 hsl(327 100% 54%)  /* numbers */
  ;
}

@media (prefers-color-scheme: dark) {
  @font-palette-values --kung-fury {
    font-family: "Monaspace";
    override-colors:
      0 hsl(188 100% 75%), /* curlies and tags */
      1 hsl(250 100% 80%), /* ? */
      2 hsl(188 100% 75%), /* function */
      3 hsl(188 100% 75%), /* ? */
      4 hsl(250 100% 80%), /* () */
      5 hsl(210 40% 98%),  /* property name */ 
      6 hsl(210 40% 80%),  /* ? */
      7 hsl(300 100% 80%)  /* numbers */
    ;
  }
}

@layer demo.support {
  * {
    box-sizing: border-box;
    margin: 0;
  }

  html {
    block-size: 100%;
    color-scheme: dark light;
    view-transition-name: none;
  }

  body {
    min-block-size: 100%;
    font-family: system-ui, sans-serif;

    display: grid;
    place-content: center;
    place-items: center;
  }
  
  pre {
    font-size: 1.5rem;
    padding: 1.5rem 2rem;
    background: hsl(280 10% 50% / 10%);
    border-radius: 10px;
    max-inline-size: max-content;
  }
  
  code {
    font-family: "Monaspace", monospace;
    font-palette: --kung-fury;
  }
}
              
            
!

JS

              
                function copyPreToStyle() {
  if (document?.startViewTransition) {
    document.startViewTransition(() => {
      document.querySelector('#pre-target').textContent = document.querySelector('pre').textContent
    })
  }
  else 
    document.querySelector('#pre-target').textContent = document.querySelector('pre').textContent
}

document.querySelector('pre').addEventListener('keyup', e => {
  clearTimeout(e.target.debouncer)  
  e.target.debouncer = setTimeout(copyPreToStyle, 500) 
})

copyPreToStyle()
              
            
!
999px

Console