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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // https://shj.rip/web-components-tutorial

class CustomSquare extends HTMLElement {
  constructor() {
    super();

    this.shadow = this.attachShadow({ mode: 'open' });

    const div = document.createElement('div');
    this.shadow.appendChild(div);
    
    console.log('Create Custom square element')
  }

  // DOM에 추가
  connectedCallback() {
    console.log('Custom square element added to page', this.parentElement.tagName);
  }

  // DOM에서 제거
  disconnectedCallback() {
    console.log('Custom square element removed from page', 'isConnected:', this.isConnected);
  }

  // DOM 이동
  adoptedCallback() {
    console.log('Custom square element moved to new page', this.parentElement.tagName);
  }

  // 애트리뷰트 변경
  attributeChangedCallback(name, oldValue, newValue) {
    console.log('Custom square element attributes changed', name);
  }

  static get observedAttributes() {
    // 애트리뷰트 이름을 담은 배열을 반환
    return ['c', 'l']; // 'c'와 'l' 애트리뷰트 변경을 감지
  }
}
customElements.define('custom-square', CustomSquare);

// 엘리먼트 생성
// - Create Custom square element
const cs = document.createElement('custom-square');

// 엘리먼트 추가
// - "Custom square element added to page" "HEAD"
document.head.appendChild(cs);

// 엘리먼트 이동
// - "Custom square element removed from page" "isConnected:" true
// - "Custom square element added to page" "BODY"
document.body.appendChild(cs);

// 애트리뷰트 변경
// - "Custom square element attributes changed" "l"
cs.setAttribute('l', '2');

// 애트리뷰트 변경 (console에 나타나지 않음)
cs.setAttribute('no', '3');

// 엘리먼트 제거
// - "Custom square element removed from page" "isConnected:" false
document.body.removeChild(cs);

              
            
!
999px

Console