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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <!-- Have to put SVG first on the page to deal with Safari 6 -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="SVGsprites">
  <defs>
    <g id="icon-search" aria-labeledby="title-search" aria-describedby="desc-search" role="image">
      <!-- viewbox: 0 0 512 512 -->
      <title id="title-search">Search:</title>
      <desc id="desc-search">Type some text to perform a search.</desc>
      <path d="M496.1 435.7l-121.3-103.1c-12.5-11.3-25.9-16.5-36.8-16 28.6-33.5 45.9-77 45.9-124.6 0-106-86-192-192-192s-192 86-192 192 86 192 192 192c47.5 0 91.1-17.3 124.6-45.9-0.5 10.8 4.7 24.2 16 36.8l103.1 121.3c17.7 19.6 46.5 21.3 64.1 3.7s15.9-46.4-3.7-64.1zM192 320c-70.7 0-128-57.3-128-128s57.3-128 128-128 128 57.3 128 128-57.3 128-128 128z"
      />
    </g>
    <g id="icon-search-line" aria-labeledby="title-search-line" aria-describedby="desc-search-line" role="image">
      <!-- viewbox: 0 0 1024 1024 -->
      <title id="title-search-line">Perform search.</title>
      <desc id="desc-search-line">Submit your search term(s).</desc>
      <path d="M640 0.2c-212.1 0-384 171.9-384 384 0 64.8 16.2 125.9 44.6 179.5l-267 266.9 0.2 0.2c-20.9 20.5-33.9 48.9-33.9 80.5 0 62.4 50.6 112.9 112.9 112.9 31.5 0 60-13 80.5-33.9l-0.1-0.1 266.9-266.9c53.6 28.5 114.8 44.8 179.7 44.8 212.1 0 384-171.9 384-384s-171.9-384-384-384zM153.4 950.3c-10.3 10.7-24.6 17.4-40.5 17.4-31.2 0-56.5-25.2-56.5-56.4 0-15.9 6.7-30.2 17.4-40.5l-0.3-0.3 258.1-258.1c22.6 30.4 49.4 57.3 79.8 79.9l-258 258zM640 704.2c-176.7 0-320-143.3-320-320 0-176.7 143.3-320 320-320 176.7 0 320 143.3 320 320 0 176.7-143.3 320-320 320zM640 160.2c8.8 0 16 7.2 16 16s-7.2 16-16 16c-106 0-192 86-192 192 0 8.8-7.2 16-16 16s-16-7.2-16-16c0-123.7 100.3-224 224-224z"
      />
    </g>
  </defs>
</svg>

<header id="Banner">
  <a href="#">Fancy Logo!</a>
  
  <form method="get" action="http://adrianroselli.com/">
    <div role="search">
      <label for="s1" aria-label="Search for:">
        <svg viewBox="0 0 512 512" preserveAspectRatio="xMidYMid meet">
          <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-search"></use>
        </svg>
      </label>
      <input type="text" value="" name="s1" id="s1" placeholder="Search…">
      <button aria-label="Perform search." type="submit">
        <svg viewBox="0 0 1024 1024" preserveAspectRatio="xMidYMid meet">
          <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-search-line"></use>
        </svg>
      </button>
    </div>
  </form>
  
</header>

<main>
  
  <h1>Responsive Progressive Accessible Vanilla Search</h1>
  
  <p>
    This is a demo for <a href="http://adrianroselli.com/2015/12/responsive-progressive-accessible-vanilla-search.html">my post of the same name</a>. Not only does the link take you to my post, it also acts as an additional tab-stop on the page so you can play with the keyboard support.
  </p>
<!--
  <h2>To-do:</h2>
  
  <ul>
    <li><strike>Search icon does nothing when clicked in Safari on a Mac, so fix that. (Required a width of at least .07em, WTF?)</strike></li>
    <li><strike>Safari 6 doesn't even show the SVG. (required SVG to appear before its display use)</strike></li>
    <li><strike>Fix submit SVG to lean on text size. (needed a font-size on the button)</strike></li>
    <li><strike>Move search out of content area.</strike></li>
    <li><strike>Fix jump on search open.</strike></li>
    <li><strike>Get tabbing working in Firefox.</strike></li>
    <li><strike>Get it working in IE (10).</strike></li>
    <li><strike>Test in Edge.</strike></li>
    <li>Figure out why there seem to be extra tab stops in IE, Edge.</li>
    <li><strike>Make it functional without any JS (as there is no preceding-sibling selector).</strike></li>
    <li><strike>Media queries for small screen (perma-expand).</strike></li>
  </ul>
-->
</main>



            
          
!

CSS

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

body {
  background-color: #6D695C;
  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAACVBMVEUAAAAAAAAAAACDY+nAAAAAA3RSTlMmDQBzGIDBAAAAG0lEQVR42uXIIQEAAADCMHj/0NdkQMws0HEeAqvwAUGJthrXAAAAAElFTkSuQmCC);
  font-size: 100%;
  color: #333;
  font-family: Lato, Arial, sans-serif;
  padding: 0;
  margin: 0;
}

a:hover, a:focus {
  color: #f00;
}

header {
  margin: 0;
  padding: .5em;
  background-color: rgba(0, 0, 0, .5);
}

header::after {
  content: "";
  display: block;
  clear: both;
  margin-bottom: 1em;
}

header a {
  display: block;
  margin: 1em 0 0 1em;
  border: 2px solid #c90;
  width: 3em;
  color: #fff;
  background-color: #000;
  padding: .25em;
  text-align: center;
  transform: rotate(-365deg);
  transition: all .5s ease-in;
}

@media all and (min-width: 24em) {

  header a {
    float: left;
    font-size: 120%;
  }

}

header a:link,
header a:visited,
header a:active,
header a:hover,
header a:focus {
  text-decoration: none;
}

header a:hover,
header a:focus {
  color: #fff;
  transform: rotate(0deg);
  border-color: #f00;
  outline: none;
}

main {
  display: block;
  box-sizing: border-box;
  width: 90%;
  margin: 1em auto;
  padding: 1em 2em;
  color: #000;
  background-color: rgba(204, 204, 204, .7);
  border: .07em solid rgba(0, 0, 0, .5);
  border-radius: .5em;
}

/* Search bits */

form {
  margin: 1em auto;
  padding: 0 1em;
}

input[type="text"] {
  padding: .5em 0;
  font-family: Lato, Arial, sans-serif;
  font-size: 100%;
}

@media all and (min-width: 24em) {

  header form {
    float: right;
  }

}

main + svg, body > svg {
  display: none;
}

/* Start the search form styles */

[role="search"] {
  box-sizing: border-box;
  border-radius: .5em;
  border: 1px solid transparent;
  padding: 0;
  /*max-width: 36em;*/
  line-height: 1.6;
  display: inline-block;
  line-height: 0;
  transition: all .2s ease-in;
  background-color: #fff;
  border: 1px solid rgba(0, 0, 0, .5);
  width: 100%;
}

[role="search"].notempty {
  background-color: #fff;
  border: 1px solid rgba(0, 0, 0, .5);
}

[role="search"]::after {
  content: "";
  display: block;
  clear: both;
}

[role="search"] label {
  display: inline-block;
  overflow: hidden;
  margin: 0;
  padding: 0 0 .5em 0;
  float: left;
  cursor: pointer;
  transition: all .2s ease-in;
  height: 1.5em; /* for IE */
  text-indent: -1000px;
  width: 0;
}

[role="search"] label svg {
  fill: #fff;
  width: 1.5em;
  margin-top: .5em; /* Must go away for IE. Ugh. */
  transition: all .2s ease-in;
}

[role="search"] input[type="text"]:focus ~ label svg,
[role="search"].notempty label svg {
  fill: transparent;
}

[role="search"] input[type="text"] {
  border: none;
  border-radius: .5em;
  background-color: transparent;
  margin: 0;
  padding: .5em .75em;
  width: 65%;
  width: calc(100% - 4em);
  transition: all .2s ease-in;
}

[role="search"] input[type="text"]:focus {
  outline: none;
  background-color: #fff; /* Needed for non-JS */
}

input::-webkit-input-placeholder {
  color: #757575; /* a11y FTW! */
}

input:-ms-input-placeholder {
  color: #757575; /* a11y FTW! */
}

input::-moz-placeholder {
  color: #757575; /* a11y FTW! */
  opacity: 1; /* https://www.quirksmode.org/blog/archives/2015/12/styling_placeho.html */
}

[role="search"] button {
  font-size: 90%; /* This allows the width in ems to scale  */
  width: 2em;
  height: auto;
  margin: .3em .25em 0 .25em;
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transition: all .2s ease-in;
  float: right;
}

[role="search"] button:hover,
[role="search"] button:focus {
  outline: none;
}

[role="search"] input[type="text"]:focus ~ button,
[role="search"].notempty button {
  float: right;
  text-indent: 0;
  width: 2em;
  display: block;
}

[role="search"] button svg {
  display: block;
  margin: 0 auto;
  padding-right: .2em;
  fill: #757575;
  width: 100%;
  height: auto;
  transition: all .2s ease-in;
}

[role="search"] button:hover svg,
[role="search"] button:focus svg {
  fill: #00f;
}

[role="search"] input[type="text"]:focus ~ button svg,
[role="search"].notempty button svg {
  /*height: 100%;*/
  /*width: 4em;*/
}

@media all and (min-width: 24em) {
  
  [role="search"] {
    background-color: transparent;
    border: 1px solid rgba(0, 0, 0, 0);
    width: auto;
  }

  [role="search"] label {
    text-indent: 0;
    width: auto;
  }

  [role="search"] input[type="text"]:focus ~ label,
  [role="search"].notempty label {
    text-indent: -1000px;
    width: 0;
  }
  
  [role="search"] input[type="text"] {
    width: .07em; /* Must have min width or Safari won't work*/
    padding: 0;
    float: left;
  }

  /*[role="search"] label:matches(:hover, :focus) /for/ input, CSS Selectors 4, 13.5. Reference combinators http://www.w3.org/TR/selectors4/#idref-combinators, no support */
  [role="search"] input[type="text"]:focus,
  [role="search"].notempty input[type="text"] {
    padding: .5em .75em;
    width: 65%;
    width: calc(100% - 5.5em); /* changed from 4em */
  }

  [role="search"] button {
    display: none;
    width: 0;
    text-indent: -1000px;
  }

  [role="search"].notempty button:hover svg,
  [role="search"].notempty button:focus svg {
    fill: #00f; /* Color for when JS fires */
  }

  [role="search"] button:hover svg,
  [role="search"] button:focus svg {
    fill: #fff; /* Color for non-JS */
  }
  
}

            
          
!

JS

            
              // Get the search field by ID
var eID = document.getElementById("s1");

// Declare the event object and set it to null
var eventObj = null;

// Add the event listeners I want to track
eID.addEventListener("focus", checkSearch, false);
eID.addEventListener("blur", checkSearch, false);
eID.addEventListener("keydown", checkSearch, false);

function checkSearch(eventObj) {
  try {
    // Get the event type from the object
    eventType = eventObj.type
    // Map the tab key to a variable
    var TABKEY = 9;
    // Get the search input text value
    eIDval = eID.value;
    // Get the parent element
    eIDparent = eID.parentElement;
    // Set a class since we are on it
    eIDparent.className = "notempty";
    // Get the button
    eIDbutton = eIDparent.getElementsByTagName('button')[0];
    // Set the button tabindex
    eIDbutton.setAttribute('tabindex', '0');
    // If the text value is not blank
    if (eIDval != '') {
      // Give it a class that will stay
      eIDparent.className = "notempty";
    }
    // If the text value is blank
    else {
      // Check if focus has left the input first
      if (eventType == 'blur') {
        // Set tabindex on button to remove from flow
        eIDbutton.setAttribute('tabindex', '-1');
        // Remove the class
        eIDparent.className = "";
      }
      // Check if user hit a key
      if (eventType == 'keydown') {
        // See if the user hit the tab key
        if (eventObj.keyCode == TABKEY) {
          // Set tabindex on button to remove from flow
          eIDbutton.setAttribute('tabindex', '-1');
        }
      }
    }
  } catch (e) {
    console.log(e);
  }
}

            
          
!
999px

Console