Pen Settings

HTML

CSS

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

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

              
                <form id="highlight-me" onsubmit="handleForm()">
  <h2>Highlighting strings with JavaScript</h2>

  <label for="text">Select Sentance: </label>
  <select name="text" id="text">
    <option>Grumpy wizards make toxic brew for the evil queen and jack.</option>
    <option>The job of waxing linoleum frequently peeves chintzy kids.</option>
    <option>Back in June we delivered oxygen equipment of the same size.</option>
    <option>Just keep examining every low bid quoted for zinc etchings.</option>
    <option>How razorback-jumping frogs can level six piqued gymnasts!</option>
    <option>A quick movement of the enemy will jeopardize six gunboats.</option>
    <option>All questions asked by five watched experts amaze the judge.</option>
    <option>Bobby Klun awarded Jayme sixth place for her very high quiz.</option>
    <option>The wizard quickly jinxed the gnomes before they vaporized.</option>
    <option>Zelda might fix the job growth plans very quickly on Monday.</option>
    <option>Zack Gappow saved the job requirement list for the six boys.</option>
    <option>Jackie will budget for the most expensive zoology equipment.</option>
    <option>Quirky spud boys can jam after zapping five worthy Polysixes.</option>
  </select>
  
  <br>
  
  <label for="highlight">Search & Highlight: </label>
  <input type="text" name="highlight" id="highlight">
  
  <br>
  <br>
  
  <button>Highlight</button>

  <div id="results"></div>
</form>
              
            
!

CSS

              
                body {
  background: #66999b;
  color: #2b3a67;
  font-family: Helvetica, san-serif;
  line-height: 2.5em;
  font-size: 1.15em;
  padding: 2em;
}

form {
  max-width: 1024px;
  margin: 0 auto;
}

input,
button,
select {
  font-size: 1.15em;
  background-color: #66999b;
  border: none;
  border-bottom: 2px solid #2b3a67;
  color: #2b3a67;
}

button {
  border: 2px solid #2b3a67;
  border-radius: 10px;
  color: #2b3a67;
  cursor: pointer;
  padding: 8px;
  background: linear-gradient(145deg, #5c8a8c, #6da4a6);
  box-shadow: 20px 20px 60px #578284, -20px -20px 60px #75b0b2;
}

              
            
!

JS

              
                function highlightText(text, highlight) {
  const regex = new RegExp(highlight, "gi");
  const results = text.replace(regex, "<b>$&</b>");

  return results;
}


/* Form handling, only look if you are interested in basic JS onsubmit handling */

function handleForm() {
  event.preventDefault();

  const myForm = document.getElementById("highlight-me");
  const formData = new FormData(myForm);
  const text = formData.get("text");
  const highlight = formData.get("highlight");

  const results = document.querySelector("#results");

  results.innerHTML = highlightText(text, highlight);
}

              
            
!
999px

Console