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

              
                <div id="mainContainer">
        <div id="tooltipContainer"></div>
        <div class="sectionContainer">
            <p>Try <i>highlighting</i> some text below</p>
            <div id="textContainer">
                <p id="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus congue condimentum ante
                    laoreet tempus.
                    Phasellus semper vitae turpis et luctus. Quisque viverra ligula quis iaculis luctus. Vivamus et nibh
                    eu
                    justo bibendum placerat. Nullam auctor fringilla risus, a eleifend purus pharetra et. Cras varius
                    arcu
                    non felis egestas, quis mollis sem ultricies. Vestibulum congue mattis sem. Suspendisse ut dui in
                    ligula
                    faucibus feugiat id suscipit risus. Donec lobortis ligula ac dictum tincidunt. Quisque lacus metus,
                    porta eu lobortis ultricies, aliquet ac mi. Maecenas lobortis mollis diam, sagittis pulvinar urna
                    mollis
                    a. Phasellus quis nibh felis. Cras porta pharetra interdum. Nam sodales purus vitae malesuada
                    sollicitudin.</p>
            </div>
        </div>
    </div>
    <script src="https://unpkg.com/@popperjs/[email protected]"></script>
    <script src="https://unpkg.com/[email protected]"></script>
    <script src="index.js"></script>
              
            
!

CSS

              
                body {
    display: grid;
  height: 100vh;
    place-items: center;
    font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
}

#mainContainer {
    width: 75vw;
}

div {
    display: grid;
    place-items: center;
}

#textContainer {
    padding: 24px;
    border-radius: 4px;
    display: grid;
    place-items: center;
    background-color: #abcbca;
}

#textContainer>p {
    color: white;
    letter-spacing: 2px;
    font-size: 16px;
}

p::selection {
    background-color: gainsboro;
    color: black;
}

#tooltipContainer {
    position: absolute;
}
              
            
!

JS

              
                const [instance] = tippy('#tooltipContainer', {
    content: 'tooltip',
    sticky: true
})

const tooltipContainer = document.getElementById("tooltipContainer");
        
document.getElementById("textContainer").addEventListener("mouseup", () => {
    let selection = document.getSelection();
    if (!selection.isCollapsed) {
        const { left, top, width, height } = selection.getRangeAt(0).getBoundingClientRect()
    
        tooltipContainer.style.left = `${left}px`
        tooltipContainer.style.top = `${top}px`
        tooltipContainer.style.width = `${width}px`
        tooltipContainer.style.height = `${height}px`

        console.log("showing")
        const numLines = selection.toString().length;
        instance.setContent(`Great Job! You selected ${numLines} charcters!`);
        instance.enable()
    }
});

document.addEventListener('mousedown', (event) => {
    console.log("hiding")
    tooltipContainer.style.width = `${0}px`
    tooltipContainer.style.height = `${0}px`
    instance.disable()
})
              
            
!
999px

Console