cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
              <div class="wrapper">
  <h1>Highlight Within Textarea v2</h1>
  <p>Highlight <input type="text" id="blue-word" value="possible"> in blue and <input type="text" id="pink-word" value="magic"> in pink.</p>
  <textarea spellcheck="false">The two words above are highlighted in this textarea. Such a thing isn't actually possible with HTML, but we can fake it with some CSS and JS magic. Go ahead, type some stuff in here or change the words above to see the real-time highlighting in action.</textarea>
</div>

            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Asap:400,700');

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  font: 1.5rem 'Asap', sans-serif;
  background-image: linear-gradient(120deg, #9890e3 0%, #b1f4cf 100%);
}

.wrapper {
  width: 650px;
  margin: 40px auto;
  text-align: center;
}

h1 {
  margin: 0 0 20px;
  font-size: 2.75rem;
  text-shadow: 2px 2px 0 rgba(255, 255, 255, 0.5);
}

p {
  margin: 0 0 40px;
}

input {
  appearance: none;
  display: inline-block;
  width: 100px;
  padding: 0;
  border: 0;
  border-bottom: 2px dashed #fff;
  border-radius: 0;
  text-align: center;
  font-size: inherit;
  font-family: inherit;
  font-weight: bold;
  background-color: transparent;
}

.hwt-container {
  background-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.2);
}

.hwt-content {
  width: 650px;
  height: 225px;
  padding: 20px;
  border: 1px solid #fff;
  text-align: left;
  font-size: 1.5rem;
  line-height: 1.5;
  
  mark {
    border-radius: 2px;
    background-color: #fcc2d7;
    box-shadow: 0 0 0 1px #fff;
    
    &.blue {
      background-color: #a3daff;
    }
    
    &.pink {
      background-color: #fcc2d7;
    }
  }
}

            
          
!
            
              // Uses highlight-within-textarea
// https://github.com/lonekorean/highlight-within-textarea

function highlightBlue() {
  return $('#blue-word').val();
}

function highlightPink() {
  return $('#pink-word').val();
}

function updateHighlights() {
  $('textarea').highlightWithinTextarea('update');
}

$('textarea').highlightWithinTextarea({
  highlight: [
    {
      highlight: highlightBlue,
      className: 'blue'
    },
    {
      highlight: highlightPink,
      className: 'pink'
    }
  ]
});

$('input').on('input', updateHighlights);

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console