Pen Settings



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


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


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.


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.


                <text-editable>click to edit</text-editable>




                class TextEditable extends HTMLElement {
    // Your element is being constructed. It is not connected to the page yet!
    // It will also be called when you use `document.createElement`
    constructor() {
        // you must call super(). The browser will remind you if you don't ;-)
        // We prepare the shadow dom so that all the inner elements are private
        // and don't interfere with the page
        this.shadow = this.attachShadow({ mode: "open" });

    connectedCallback() {
        // populate our shadow dom with our style and html
        this.shadow.innerHTML = `
        // keep a reference of the main elements in the html
        this.span = this.shadow.querySelector("span");
        this.input = this.shadow.querySelector("input");
        this.div = this.shadow.querySelector("div");

        // Add listeners to the different elements
            (this.onTextClickedListener = this.onTextClicked.bind(this))
            (this.onInputBlurListener = this.onInputBlur.bind(this))
            (this.onKeyPressListener = this.onKeyPress.bind(this))

    onTextClicked() {
        // copy the text to the input element
        this.input.value = this.textContent;
        // show the input field

    onInputBlur() {
        // just restore the normal text without changing it

    onKeyPress(e) {
        if (e.code === "Enter") {
        } else if (e.code === "Escape") {

    // Save the value from the field
    commitValue() {
        // copy the text from the input field to the element itself
        this.textContent = this.input.value;
        // dispatch an event to let the outside world we updated the text
        this.dispatchEvent(new CustomEvent("update"));
        // show the normal text

    // Show the input field or the static text according to the passed parameter
    switchMode(mode) {
        if (mode === "edit") {
   = "none";
   = "inline-block";
        } else {
   = "inline-block";
   = "none";

    // Return the HTML to populate our component. Note the usage of the `<slot>`
    // tag: it references the child nodes of our web components
    getHtml() {
        return `
                <input class="field"/>

    // Returns the style to use inside the shadow DOM. These rules will only affect
    // the elements inside the shadow DOM!
    getStyle() {
        return `
            :host {
                cursor: pointer;
            div {
                display: none;

    // Nicely cleanup the event listeners when the node get disconnected
    disconnectedCallback() {
        this.span.removeEventListener("click", this.onTextClickedListener);
        this.input.removeEventListener("blur", this.onInputBlurListener);
        this.input.removeEventListener("keyup", this.onKeyPressListener);
// Declare our new web component
customElements.define("text-editable", TextEditable);