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


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


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.


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.


                <h2>Attribute Selection with JavaScript</h2>
<p>Here we use document.querySelectorAll to select the image with an alt attribute that contains "rulers", adding the class "selected" via the .classList method. </p>
<div class="gallery">
<img src="//" alt="old-fashioned rulers">
<img src="//" alt="manual cameras">
<img src="//" alt="rad typography booklets">

<h2>Attribute Selection with jQuery</h2>
<p>Here we select the image with a data attribute that starts with "out". The original image is replaced by an alternate image with jQuery, and the caption gets a little extra text as :after content with CSS. </p>
<img src="//" alt="old-fashioned rulers" data-availability="in-stock">
  <figcaption>Old-Fashioned Rulers</figcaption>
<img src="//" alt="manual cameras" data-availability="in-stock">
    <figcaption>Manual Cameras</figcaption>
<img src="//" alt="rad typography booklets" data-availability="out-of-stock">
  <figcaption>Type Booklets</figcaption>


                .selected {
  outline: 5px solid #E18728;
  outline-offset: 2px;

img[data-availability^="out"] + figcaption:after { /* if an image's data-availability starts with "out", add an "out of stock" message after its caption. See the JS tab for how the image was replaced. */
  font-style: italic;
  content: ' - out of stock';
  color: red;

/* styling for Pen,  not related to attribute selectors */

body { 
  font-family: sans-serif;
  width: 90%;
  margin: 0 auto;
  line-height: 1.5;

figure { 
  margin: 1em .5em;
  float: left;
  text-align: center;

.gallery img:not(:last-child) { margin-right: 1em; }

hr { clear: both; }


                /* Just JavaScript */
var nose = document.querySelector('img[alt*="rulers"]');

/* jQuery */
$( document ).ready(function() {
  /* replacing original product image with "Out of Stock" image */
    'src' : '//',
    'alt' : 'out of stock'