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

              
                <div class="line--clamp" id="box">
  <p>What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
  <p dir="rtl">الكلمة الافتتاحية للمدير العام لمنظمة الصحة العالمية في جلسة الاستماع العامالمتعلقة بوضع صك دولي جديد بشأن التأهب والاستجابة للجائحة - 12 نيسان/ نيسان/أبريل 2022. ولكن حتى ونحن نعمل على القضاء على هذه الجائحة، فإننا ندين لأولئك الذين لقوا حتفهم بسببها وأولئك الذين تضرروا منها بتعلم الدروس المؤلمة التي تقدمها لنا وإدخال التغييرات التي يجب أن نجريها للتأكد من أن العالم متأهب على نحو أفضل للجائحة التالية.</p>
</div>

<form>
  <input type="checkbox" id="height" name="height">
  <label for="height">height: </label>
  <input type="range" min="2" max="10" value="4" step="1" name="height-value" id="height-value" disabled>
  <output id="output-height-value">2rem</output>

</form>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

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

body {
  width: 100vw;
  min-height: 100vh;
  font-family: "Exo", Arial, sans-serif;
  background-color: #557;
  color: #fff;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: var(--gap);
}
form {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 2rem;
  background: rgb(16 18 27 / 40%);
  backdrop-filter: blur(20px);
  font-family: "Exo", Arial, sans-serif;
}

label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 0.25em;
  position: relative;
  line-height: 1;
  color: #cbcbcb;
  font-family: "Exo", Arial, sans-serif;
}

input[type="checkbox"] {
  height: 1px;
  overflow: hidden;
  width: 1px;
  position: absolute;
  clip-path: inset(50%);
}

label::before {
  content: "";
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border-radius: 4px;
  border: 1px solid #cbcbcb;
  background: #fff;
  color: #cbcbcb;
  width: 24px;
  aspect-ratio: 1;
  transition: all 0.2s ease;
}

input[type="checkbox"]:checked + label {
  color: #fff;
}

input[type="checkbox"]:checked + label::before {
  content: "✔";
  border-color: #0075ff;
  background-color: #0075ff;
  color: #fff;
  font-size: 0.75em;
}

input[type="range"]:disabled {
  cursor: not-allowed;
  pointer-events: none;
}

input[type="range"]:disabled + output {
  color: #cbcbcb;
}

.line--clamp {
  inline-size: 50vw;
  border: 1px solid #f9f9f9;
  border-radius: 4px;
  box-shadow: 0 0 1px rgb(0 0 0 / 0.4);
  padding: 2rem;
  margin: auto;
  background-color: rgb(0 0 0 / 0.5);
  backdrop-filter: blur(20px);
}

.line--clamp p {
  letter-spacing: 0.0125em;
  hyphens: auto;
  text-shadow: 1px 1px 0 rgb(0 0 0 / 50%);
  font-size: 1.25em;
  line-height: 1.6;
  color: #f5f5f5;
}

h2 {
  font-size: clamp(1.2rem, 2vw + 1.5rem, 2rem);
}

.line--clamp > * + * {
  margin-block-start: 2rem;
}

.line--clamp p {
  background-color: rgb(120 123 190 / 0.5);
  backdrop-filter: blur(30px);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--line-clamp, 2);
  overflow: var(--overflow, hidden);
  height: var(--height, auto);
}

              
            
!

JS

              
                let lineClampBox = document.getElementById("box");
const checkBox = document.getElementById("height");
const heightValue = document.getElementById("height-value");
const heightValueOutput = document.getElementById("output-height-value");

checkBox.addEventListener("change", (etv) => {
  if (checkBox.checked) {
    heightValue.removeAttribute("disabled");
    lineClampBox.style.setProperty(`--height`, `${heightValue.value}rem`);
    heightValueOutput.textContent = `${heightValue.value}rem`;
  } else {
    heightValue.setAttribute("disabled", true);
    lineClampBox.style.setProperty(`--height`, `auto`);
  }
});

heightValue.addEventListener("change", (etv) => {
  lineClampBox.style.setProperty(`--height`, `${etv.target.value}rem`);
  heightValueOutput.textContent = `${etv.target.value}rem`;
});

              
            
!
999px

Console