Skip to content

Read More Clamp Toggle

A copy-paste css-only interactions component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.

CSS-Only InteractionsHTMLCSSany framework

Copy into your project

HTML
<!-- Read More Clamp Toggle — checkbox + :has() flips -webkit-line-clamp, zero JS -->
<div class="nuda-co2-clamp-toggle">
  <input class="nuda-co2-clamp-toggle__input" type="checkbox" id="co2-clamp-1" />
  <p class="nuda-co2-clamp-toggle__text">
    NudaUI ships copy-paste CSS components with zero runtime dependencies. Every interaction in this
    category — accordions, tabs, dropdowns, this very clamp — runs on native selectors alone, so the
    snippet you copy is the entire implementation, nothing hides behind a bundle.
  </p>
  <label class="nuda-co2-clamp-toggle__toggle" for="co2-clamp-1">
    <span class="nuda-co2-clamp-toggle__txt-more">Read more</span>
    <span class="nuda-co2-clamp-toggle__txt-less">Read less</span>
  </label>
</div>
CSS
.nuda-co2-clamp-toggle {
  --nuda-co2-ct-accent: #e4ff54;
  width: 100%;
  max-width: 300px;
  font-family: inherit;
}

.nuda-co2-clamp-toggle__input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

.nuda-co2-clamp-toggle__text {
  position: relative;
  margin: 0 0 .4rem;
  font-size: .76rem;
  line-height: 1.55;
  color: #bbb;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

.nuda-co2-clamp-toggle__text::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1.6em;
  background: linear-gradient(to bottom,rgba(9,9,11,0),#09090b);
  opacity: 1;
  transition: opacity .25s ease;
}

.nuda-co2-clamp-toggle__toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: .4rem .1rem;
  font-size: .72rem;
  font-weight: 700;
  color: var(--nuda-co2-ct-accent);
  cursor: pointer;
}

.nuda-co2-clamp-toggle__toggle:hover {
  text-decoration: underline;
}

.nuda-co2-clamp-toggle__toggle .nuda-co2-clamp-toggle__txt-less {
  display: none;
}

.nuda-co2-clamp-toggle__input:focus-visible~.nuda-co2-clamp-toggle__toggle {
  outline: 2px solid var(--nuda-co2-ct-accent);
  outline-offset: 2px;
  border-radius: 5px;
}

.nuda-co2-clamp-toggle:has(.nuda-co2-clamp-toggle__input:checked) .nuda-co2-clamp-toggle__text {
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: visible;
}

.nuda-co2-clamp-toggle:has(.nuda-co2-clamp-toggle__input:checked) .nuda-co2-clamp-toggle__text::after {
  opacity: 0;
}

.nuda-co2-clamp-toggle:has(.nuda-co2-clamp-toggle__input:checked) .nuda-co2-clamp-toggle__txt-more {
  display: none;
}

.nuda-co2-clamp-toggle:has(.nuda-co2-clamp-toggle__input:checked) .nuda-co2-clamp-toggle__txt-less {
  display: inline;
}

@media (prefers-reduced-motion:reduce) {
  .nuda-co2-clamp-toggle__text::after {
    transition: none;
  }
}

How to use Read More Clamp Toggle

Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.

Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.

More css-only interactions components

← Browse all NudaUI components