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.

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

              
                <h1 class="resize-me">Resize the window</h1>

<div class="container">
  <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ad voluptatum quo vel ipsa doloremque. Ducimus illum illo tempore qui possimus explicabo velit, voluptatem sapiente dolores aspernatur beatae vel ullam veniam natus. Vero doloremque quo voluptas est pariatur dolorum, tenetur quas aperiam repudiandae at. Accusamus molestiae sequi deserunt. Consectetur, sint aut.</p>
  <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Est eveniet nobis voluptas dignissimos, minus quae debitis? Dolorem nam itaque, mollitia ab eius, tenetur temporibus sunt nulla quisquam excepturi eos vel?</p>
  
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo voluptates sapiente maxime nam, voluptatem eius magnam perspiciatis, iste velit excepturi voluptas eveniet, sed dolores adipisci nesciunt doloribus asperiores aliquam ipsa laborum praesentium fugit voluptatibus? Asperiores repellendus enim nisi placeat recusandae, in eos dolorem error mollitia ullam cupiditate reprehenderit delectus. Natus.</p>
</div>

              
            
!

CSS

              
                body{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  height: 100vh;
  width: 100%;
  display: grid;
  place-items: center;
  position: relative;
}

.resize-me{
  position: absolute;
  left: 0;
  writing-mode: vertical-lr;
}

.container{
  width: 80%;
  margin: 0 auto;
  
  p{
    font-size: 2.5rem;
  }
}


              
            
!

JS

              
                function widowSlayer(){
  const pTag = document.querySelectorAll('p');

  pTag.forEach(tag => {
    // 1. Split all the words from the p tag from anytime there's a space
    const words = tag.innerHTML.split(' ');
    // 2. Find the last space and insert a &nbsp; in it's place
   const lastWordsList = words.slice(-1) && words.splice(-2);
    // 3. Join the last two togehter with a &nbsp;
   tag.innerHTML = words.join(' ') + ' ' + lastWordsList.join('&nbsp;');
  })
}

widowSlayer()


              
            
!
999px

Console