Pen Settings

HTML

CSS

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

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

Auto Save

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

              
                <body>
    <div class="container">
        <nav>
            <h1>Virtual assistant</h1>
            <p>Our virtual assistant is ready to assist you, making your online
                experience seamless and enjoyable
            </p>
        </nav>
        <div class="chat">
            <div class="santaSays">
                <div class="img-box">
                    <img src="https://img.freepik.com/free-vector/funny-santa-claus-celebrating-christmas_74855-962.jpg" alt="santaimg">
                </div>
                <div class="text-box-santa">
                    <div class="text">
                        <p>Hi there, my child!</p>
                        <p>What can I help you with?</p>
                    </div>
                </div>
            </div>
            <div class="userSays">
                <div class="text">
                    <p>Hello, Santa!</p>
                    <p>I'd like to know when you'll bring my gift?</p>
                </div>
            </div>
        </div>
        <hr>
        <div class="message-box">
            <div class="message-input">
                <input id="inputText" type="text" placeholder="What can I help you with?">
            </div>
            <div class="send-btn">
                <i class="fa-solid fa-paper-plane plane"></i>
            </div>
        </div>
    </div>

    <script src="app.js"></script>
</body>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');

*,
*:before,
*:after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    font-size: 62.5%;
}

body {
    background-color: #9ca6b0;
    font-family: 'Poppins', sans-serif;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    width: 100%;
    max-width: 400px;
}

nav {
    background-color: #227393;
    color: #fff;
    padding: 2.5rem;
    text-align: center;
    border-radius: 6px 6px 0 0;
}

nav>h1 {
    font-size: 2.5rem;
}

nav>p {
    margin-top: .5rem;
    font-size: 1.4rem;
    color: #e2e4e6;
}

.chat {
    font-size: 1.6rem;
    background-color: #fff;
    padding: 5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-height: 439px;
    overflow: hidden;
}

.chat::-webkit-scrollbar {
    width: 0 !important;
}

.chat {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.chat:hover {
    overflow: hidden;
    overflow-y: scroll;
}
@media (max-width: 400px) {
    .chat {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
}

img {
    width: 50px;
}

.santaSays {
    display: flex;
    align-items: end;
    gap: 1.3rem;
}

.text-box-santa>.text>p {
    background-color: #eff3f6;
    padding: 1.3rem;
    width: fit-content;
    max-width: 250px;
    border-radius: 1px;
}

.text-box-santa>.text>p:not(.text-box-santa>.text>p:nth-of-type(1)) {
    margin-top: 1.5rem;
}

.userSays {
    margin-top: 3rem;
}

.userSays>.text {
    display: flex;
    flex-direction: column;
    align-items: end;
}

.userSays>.text>p {
    background-color: #dff4fc;
    padding: 1.3rem;
    width: fit-content;
    max-width: 250px;
    border-radius: 1px;
}

.userSays>.text>p:not(.userSays>.text>p:nth-of-type(1)) {
    margin-top: 1.5rem;
}

hr {
    border: none;
    border-top: 1px solid #f0efefe7;
}

.message-box {
    padding-top: 1rem;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 2rem;
    border-radius: 0 0 6px 6px;
}

.message-input {
    width: 100%;
}

#inputText {
    border: none;
    padding: 1rem 0;
    font-family: 'Poppins', sans-serif;
    width: 100%;
    font-size: 1.6rem;
    outline: none;
}

.plane {
    font-size: 2rem;
    color: #227393;
    cursor: pointer;
}

.userMessage {
    background-color: #dff4fc;
    padding: 1.3rem;
    width: fit-content;
    max-width: 250px;
    border-radius: 1px;
    margin-left: auto;
    word-wrap: break-word;
}

.santaMessage {
    background-color: #eff3f6;
    padding: 1.3rem;
    width: fit-content;
    max-width: 250px;
    border-radius: 1px;
    word-wrap: break-word;
}
              
            
!

JS

              
                


const chat = document.querySelector(".chat");
const inputText = document.getElementById("inputText");
const btn = document.querySelector(".plane");


const santaPhrases = [
    "No gifts for you this year.",
    "You've been a naughty kid.",
    "Wait until next year for your presents",
    "I don't feel like arguing",
    "Give me some fucking milk and biscuits",
    "Where's my damn reindeer?"
]

btn.addEventListener("click", () => {
    let random = Math.floor(Math.random() * santaPhrases.length);
    let santaSays = santaPhrases[random];

    let pU = document.createElement("p");
    pU.innerHTML = inputText.value;
    pU.classList.add("userMessage");
    chat.appendChild(pU);
    inputText.value = "";
    chat.scrollTop = chat.scrollHeight;

    let typing = document.createElement("p");
    typing.innerHTML = "Santa is typing...";
    typing.style.fontSize = "1.3rem";
    chat.appendChild(typing);
    setTimeout(() => {
        let pS = document.createElement("p");
        pS.innerHTML = santaSays;
        pS.classList.add("santaMessage");
        chat.appendChild(pS);
        chat.scrollTop = chat.scrollHeight;
        chat.removeChild(typing);
    }, 2000);
})



inputText.addEventListener("keyup", (e) => {
    if (e.key === "Enter") {
        let random = Math.floor(Math.random() * santaPhrases.length);
        let santaSays = santaPhrases[random];

        let pU = document.createElement("p");
        pU.innerHTML = inputText.value;
        pU.classList.add("userMessage");
        chat.appendChild(pU);
        inputText.value = "";
        chat.scrollTop = chat.scrollHeight;

        let typing = document.createElement("p");
        typing.innerHTML = "Santa is typing...";
        typing.style.fontSize = "1.3rem";
        chat.appendChild(typing);
        setTimeout(() => {
            let pS = document.createElement("p");
            pS.innerHTML = santaSays;
            pS.classList.add("santaMessage");
            chat.appendChild(pS);
            chat.scrollTop = chat.scrollHeight;
            chat.removeChild(typing);
        }, 2000);
    }
})
              
            
!
999px

Console