Pen Settings



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


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.


  <h2>Multi-line Elipsis: Cross-Browser Javascript and CSS Solution</h2>
    <p>The text below will be truncated with an ellipsis in all browsers. This relies on a bit of Javascript and some CSS to set the number of lines to hide. The Javascript for this pen will loop through all instances on a page but if you only need to handle one instance, you can remove the <code>.forEach</code> and just have it check one.</p>
  <div class="container">
    <p>There's a lot more text in here than what you'll ever see. Pellentesque habitant testalotish morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>
  <div class="container">
    <p>Not much text? No clipping.</p>
  <div class="container">
    <p>Just a couple of lines of text? It'll likely be shown in its entirety on a wider window but as you shrink down it'll continue to truncate to two lines like you'd expect. That's the difference between this and other solutions I've seen.</p>
  <p>I'd recommend adding a window resize event listener in here but I'm trying o keep this pen simple. If you need a CSS only version, check out <a href="">my other pen on the topic here</a>.</p>


                /* Up here is all the styles to make this pen not look crappy. The meat of this is down below. */
@import ',300,400,700';

body {
  font-family: Raleway;
  font-weight: 400;
  background: lightCyan;
  display: flex;
  justify-content: center;

section {
  width: 80%;
  margin: auto;

h2 {
  text-align: center;

/* This is the important part - particularly the height of the .container */
.container {
  border: 1px solid lightGrey;
  padding: 0 1.5em;
  border-radius: 3px;
  background: #fff;
  margin-bottom: 2em;
  // width: 300px; // Width is optional - works with or without
  height: 3em; // Use multiples of the line-height (1.5em)
  overflow: hidden; 
  line-height: 1.5em;

.container p { 
  padding: 0; 
  margin: 0; 


                const containers = document.querySelectorAll('.container');, (container) => {  // Loop through each container
    var p = container.querySelector('p');
    var divh = container.clientHeight;
    while (p.offsetHeight > divh) { // Check if the paragraph's height is taller than the container's height. If it is:
        p.textContent = p.textContent.replace(/\W*\s(\S)*$/, '...'); // add an ellipsis at the last shown space