Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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.


                <!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Aquarium Filter</title>
    <link rel="stylesheet" href="./styles.css" />
    <div id="filters">
        <button id="fish">🐠</button>
        <button id="bird">🐦</button>
        <button id="all">all</button>

    <div id="grid">
        <img class="bird" src="" alt="An adult Common Waxbill on Gran Canaria, Spain." />
        <img class="bird" src="" alt="Semipalmated sandpiper" />
        <img class="fish" src="" alt="Chromis atripectoralis 2" />
        <img class="fish" src="" alt="Goldsaddle goatfish" />
        <img class="bird" src="" alt="A wild Black-headed Munia on Cebu, Philippines." />
        <img class="fish" src="" alt="チャイロヤッコ Centropyge fisheri" />
        <img class="bird" src="" alt="Yellow-billed cuckoo" />
        <img class="fish" src="" alt="Scrawled Filefish" />
        <img class="bird" src="" alt="Hawaiʻi ‘elepaio" />
        <img class="bird" src="" alt="Scaly-breasted munia in Nagarhole National Park" />
        <img class="bird" src="" alt="Chestnut munia" />
        <img class="fish" src="" alt="フタイロハナゴイyg Pseudanthias bicolor" />
        <img class="fish" src="" alt="Centropyge interruptus in Kashiwajima Kohchi-ken(Prefecture), Japan" />
        <img class="bird" src="" alt="Puaiohi" />
        <img class="bird" src="" alt="♀ Falcated Duck (Anas falcata) at Sylvan Heights Waterfowl Park in Scotland Neck, North Carolina.">
        <img class="bird" src="" alt="Japanese white-eye" />
        <img class="bird" src="" alt="Lavender waxbill (Estrilda caerulescens), The Gambia" />
        <img class="fish" src="" alt="Flame angelfish" />
        <img class="bird" src="" alt="Zebra dove" />
        <img class="bird" src="" alt="Red-crested cardinal" />
        <img class="bird" src="" alt="Millerbird" />
        <img class="fish" src="" alt="Chaetodon lineolatus Great Barrier Reef, Cairns, Australia" />

    <script src="./script.js" type="text/javascript"></script>


                body {background-color: #ebebeb;}

/* Filters */
#filters {
    margin-bottom: 1em;
    display: flex;
    flex-flow: row nowrap;
    gap: 5px;
#filters button {
    font-size: 20px;
    /* background: #fff; */
    /* border: 1px dotted #000; */
    height: 2em;
    border-radius: 3px;
    cursor: pointer;

/* Grid */
#grid {
    display: grid;
    grid-template-columns: repeat(4, 200px);
    gap: 10px;
#grid img {
    max-width: 100%;


                // Let's declare our global constants
const filters = document.querySelectorAll('#filters');
const images = document.getElementsByTagName('img');

// Our little program that finds all the elements with the corresponding filter class and displays them
function filterImages(filterBy) {
    // Hide all our images so we can only show the filtered ones
    for (let image of images) { = 'none';

    // A if/else statement for the 'all' filter
    if (filterBy === 'all') {
        animals = images;
    } else {
        animals = document.querySelectorAll('.' + filterBy);

    // Finally show the filtered images
    for (let animal of animals) { = 'block';

// Loop through the filters and add an event listener to each filter button
for (let filter of filters) {
    filter.addEventListener('click', function(event) {
        // Get the id from the clicked filter button
        var filterBy ='id');
        // See how we are passing `filterBy` into the function here