Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

  Click and drag to highlight elements below. The text will highlight and be seen in the form field and as a URL parameter.

  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Qua tu etiam inprudens utebare non numquam. Hoc est non dividere, sed frangere. Tecum optime, deinde etiam cum mediocri amico. Polemoni et iam ante Aristoteli ea prima visa sunt, quae paulo ante dixi. Non est igitur summum malum dolor. Quae cum praeponunt, ut sit aliqua rerum selectio, naturam videntur sequi; Duo Reges: constructio interrete. Cum autem in quo sapienter dicimus, id a primo rectissime dicitur.

Eadem fortitudinis ratio reperietur. Sed ea mala virtuti magnitudine obruebantur.

  <input type="text" name="highlight" id="hi"><br> 

<a id="my-link" href=""></a>
              body {
  width: 700px;
  padding: 2em;
  margin: 0 auto;

#hi {
  width: 50%;
  height: 3em;

.active {
  margin: 2em 0;
  border: 1px solid;
  padding: .5em;

#my-link:hover {
  background-color: #efefef;
              // modified a bit from https://jsfiddle.net/timdown/SW54T/
//other thing used was https://stackoverflow.com/questions/5809310/jquery-how-do-i-apply-css-to-selected-text

var url = window.location.href;

//get highlighted text
function getSelectedText() {
        var text = "";
        if (typeof window.getSelection != "undefined") {
            text = window.getSelection().toString();
        } else if (typeof document.selection != "undefined" && document.selection.type == "Text") {
            text = document.selection.createRange().text;
        return text;

//set the form field and build the a href link
    function setField() {
        var selectedText = getSelectedText();
        var field = document.getElementById('hi');
        var link = document.getElementById('my-link');
        if (selectedText) {
            field.value = getSelectedText();
            link.href = 'https://foo.com/?highlight='+encodeURIComponent(selectedText)+'&url='+url; //builds URL
            link.innerHTML = "Submit";//sets text for the button
            link.classList.add("active"); //adds a class to the link to make it prettier
    document.onmouseup = setField;
    document.onkeyup = setField;

//adds/removes highlighting background color
function highlightIt(){
  var b = document.getElementsByTagName('span');
while(b.length) {
    var parent = b[ 0 ].parentNode;
    while( b[ 0 ].firstChild ) {
        parent.insertBefore(  b[ 0 ].firstChild, b[ 0 ] );
     parent.removeChild( b[ 0 ] );

  var range = window.getSelection().getRangeAt(0);
  var newNode = document.createElement("span");
  newNode.style.backgroundColor = "yellow";
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.