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 id="mi-id">Externo</h1>

<template>
  <style>
    :host {
      display: block;
      border: 1px solid green;
      margin-bottom: 2rem;
    }
    
    h1#mi-id {
      margin-left: 1rem;
      margin-right: 1rem;
      border: 1px solid green;
    }
  </style>
  <h1 id="mi-id">Hola, Jaime Cervantes</h1>
  <p>¿Cómo estas?</p>
</template>

<mi-saludo></mi-saludo>
<mi-saludo></mi-saludo>
<mi-saludo></mi-saludo>
<mi-saludo></mi-saludo>

              
            
!

CSS

              
                h1#mi-id {
  margin-left: 20rem;
  border: 1px solid red;
}
              
            
!

JS

              
                class MiSaludo extends HTMLElement {
  constructor () {
    // Obtengo la única etiqueta 'template'
    const tpl = document.querySelector('template');
    // Clono su contenido y se crea una instancia del document fragment
    const tplInst = tpl.content.cloneNode(true);
    
    super(); // invoca el constructor de la clase padre
    // Se crea un shado dom para las instancias de mi-saludo
    this.attachShadow({ mode: 'open'});
    // Y se agrega el template dentro del shadow DOM usando el elemento raíz 'shadowRoot'
    this.shadowRoot.appendChild(tplInst);
  }
}

// Se registra el custom element para poder ser utilizado declarativamente en el HTML o imperativamente mediante JS
customElements.define('mi-saludo', MiSaludo);
              
            
!
999px

Console