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

Save Automatically?

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

              
                <body>
  <div>
    If you can't see anything enable web component support. <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components#Enabling_Web_Components_in_Firefox">Enable Web Components in Firefox</a>
  </div>

  <person-data person-fname="Billy" person-lname="Bob" person-phone="90909090" person-link-href="http://some-link-here" person-link-text="click me">
  </person-data>
  <p>
    <a href='#' onclick='changeAttribute()'>Change attribute</a>
  </p>
  
</body>
              
            
!

CSS

              
                
              
            
!

JS

              
                // Reference to shadow dom
var shadow;
// Create a new object based of the HTMLElement prototype
var PersonDataProto = Object.create(HTMLElement.prototype);

PersonDataProto.attributeChangedCallback = function(attrName, oldVal, newVal) {
  alert('Attribute ' + attrName + ' changed from ' + oldVal + ' to ' + newVal);
  shadow.getElementById('person-lname').textContent = newVal;
};
// Set up the element.
PersonDataProto.createdCallback = function() {
  // Create a Shadow Root
  shadow = this.createShadowRoot();

  var p = document.createElement('p');
  p.innerText = this.getAttribute('person-fname');
  shadow.appendChild(p);

  var p = document.createElement('p');
  p.innerText = this.getAttribute('person-lname');
  p.setAttribute('id','person-lname');
  shadow.appendChild(p);

  var p = document.createElement('p');
  p.innerText = this.getAttribute('person-phone');
  shadow.appendChild(p);

  var link = document.createElement('a');
  link.innerText = this.getAttribute('person-link-text');
  link.href = this.getAttribute('person-link-href');
  link.className = 'person-name';

  link.addEventListener('click', function(event) {
    alert('hey, don\'t know where that is' + event);
    event.preventDefault();
  });
  shadow.appendChild(link);
};
// Register the new element.
var Person = document.registerElement('person-data', { // deprecated, use customElements.define() instead
  prototype: PersonDataProto
});

function changeAttribute() {
  var person = document.getElementsByTagName('person-data');
  person[0].setAttribute('person-lname', 'Thornton');
}
              
            
!
999px

Console