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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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.

HTML

              
                <div id="postWrap"></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap');
body {
    font-family:'Montserrat', sans-serif;
}

#postWrap {
    width: 90%;
    border: 3px double #aaa;
    padding: 10px;
    margin: auto;
}
.error {
    color: #f00;
    text-align: center;
    font-weight: bold;
}
              
            
!

JS

              
                function randomNum(x) {
    return Math.round(Math.random() * x);
}
const posts = [{
    title: '1. About Lorem ipsum',
    body: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Odio corporis veritatis unde libero nesciunt esse? Consectetur nostrum suscipit quae pariatur porro aut! Iure, aperiam at.'
}, {
    title: '2.How to use Lorem ipsum?',
    body: 'Consequatur delectus sint, accusantium assumenda quaerat dicta temporibus aut ex qui, possimus vitae. Sit vero tempore aspernatur possimus dolorum qui expedita saepe ab. Assumenda, dolore?'
}]

function showPosts() {

    setTimeout(() => {
        let output = '';
        posts.forEach((post, index) => {
            output += `<h3>${post.title}</h3>
<p>${post.body}</p>
<a href="#">Read More</a>`;
        });
        postWrap.innerHTML = output;
    }, 1000)
}
showPosts();

function createPost(post) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            posts.push(post);

            const error = randomNum(1);
            if (!error) resolve();
            else reject("Sorry, an error has occurred. Post not added");
        }, 2000)
    })
}

createPost({
        title: '3.What wrang with Lorem ipsum?',
        body: 'Eius nulla unde recusandae pariatur incidunt amet ducimus tempora eaque vero tempore quod fugiat corporis, in, excepturi eum vel, adipisci modi architecto. Possimus, ullam voluptatum.'
    }).then(showPosts)
    .catch(err => postWrap.innerHTML += `<p class="error">${err}</p>`);
              
            
!
999px

Console