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

            
              <!-- 

Please enable your microphone.

Please close any other tabs/windows containing speech API projects, even if only showing the preview window. 

-->

<h1>Say Color:</h1>

<div class="color-cube">
    <div class="cube-face cube-front"></div>
    <div class="cube-face cube-back"></div>
    <div class="cube-face cube-bottom"></div>
    <div class="cube-face cube-top"></div>
    <div class="cube-face cube-left"></div>
    <div class="cube-face cube-right"></div>
</div>

<p class="color-name">orange</p>

<p class="heard-output">Heard: orange</p>

<p class="confidence-output">Confidence: 100.0%</p>

<a class="colors-list" href="https://htmlcolorcodes.com/color-names/#names" target="_blank">List of colors</a>
            
          
!

CSS

            
              * {
    box-sizing: border-box;
}

body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-family: 'Roboto', Arial, sans-serif;
    text-align: center;
    min-height: 100vh;
    background-color: #fbfbfb;
    padding: 15px;
    color: #111;
    perspective: 1000px;
    text-shadow: 0.05em 0.05em 0.05em rgba(0, 0, 0, 0.1);
}

h1 {
    font-size: 50px;
    font-weight: 500;
    margin-bottom: 50px;
}

.color-cube {
    --cube-color: orange;
    position: relative;
    width: 140px;
    height: 140px;
    transform-style: preserve-3d;
    transform: rotateX(-20deg) rotateY(-40deg);
    animation: rotateCube 5s linear infinite;
}

.cube-face {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px solid rgba(0, 0, 0, 0.4);
    background-color: var(--cube-color);
    transition: background-color 500ms;
}

.cube-front {
    transform: translateZ(70px);
}

.cube-back {
    transform: rotateY(180deg) translateZ(70px);
}

.cube-bottom {
    transform: rotateX(-90deg) translateZ(70px);
}

.cube-top {
    transform: rotateX(90deg) translateZ(70px);
}

.cube-left {
    transform: rotateY(-90deg) translateZ(70px);
}

.cube-right {
    transform: rotateY(90deg) translateZ(70px);
}

.color-name {
    font-size: 40px;
    font-weight: 500;
    margin: 55px 0 30px;
}

.heard-output,
.confidence-output {
    font-size: 22px;
    font-weight: 400;
    margin-bottom: 18px;
}

.colors-list {
    font-size: 20px;
    font-weight: 700;
    color: #111;
    text-decoration: none;
    border-bottom: 2px solid #111;
    margin-top: 10px;
}

@keyframes rotateCube {
    to {
        transform: rotateX(-20deg) rotateY(-400deg);
    }
}
            
          
!

JS

            
              //DOM load event
window.addEventListener("DOMContentLoaded",	() => {

    //Check that page is not running in a CodePen preview iframe

    //Set speech recognition
    window.SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;

    const recognition = new SpeechRecognition(),
          colorName = document.querySelector('.color-name'),
          colorCube = document.querySelector('.color-cube'),
          heardOutput = document.querySelector('.heard-output'),
          confidenceOutput = document.querySelector('.confidence-output'),
          cssColorNames = ["aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown", "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod", "darkgray", "darkgrey", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkslategrey", "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", "dodgerblue", "firebrick", "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite", "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew", "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgrey", "lightgreen", "lightpink", "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta", "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin", "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered", "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue", "slateblue", "slategray", "slategrey", "snow", "springgreen", "steelblue", "tan", "teal", "thistle", "tomato", "transparent", "turquoise", "violet", "wheat", "white", "whitesmoke", "yellow", "yellowgreen"];

    //Start speech recognition
    recognition.start();

    //Listen for when the user finishes talking
    recognition.addEventListener('result', e => {

        //Get transcript of user speech & confidence percentage
        const transcript = e.results[0][0].transcript.toLowerCase().replace(/\s/g, ''),
              confidence = (e.results[0][0].confidence * 100).toFixed(1);

        //Check if transcript is valid color value
        if(cssColorNames.includes(transcript)) {

            //Set cube color;
            colorCube.style.setProperty('--cube-color', transcript);

            //Set color name text value
            colorName.textContent = transcript;

        }

        //Output transcript
        heardOutput.textContent = `Heard: ${transcript}`;

        //Output transcript confidence percentage
        confidenceOutput.textContent = `Confidence: ${confidence}%`;

    });

    //Restart speech recognition after user has finished talking
    recognition.addEventListener('end', recognition.start);
    
});
            
          
!
999px

Console