Newsletter

Hear about new files and fixes

I send an email when I publish something new or release a fix for a file you might already use. There’s no fixed schedule.

Every email has a one-click unsubscribe link, and none of them contain tracking pixels.

Etch component

Read More

Collapses long text or rich content to a short preview with a Read more button. The button appears only when the content is taller than the height you set, and the fade blends into any background. It works with the keyboard and screen readers, in Etch loops and with content loaded by AJAX. You set it up in the Etch props panel and style it with CSS variables.

Download .jsonSee the demo

Paste it on the Etch canvas with Ctrl+V or ⌘V, then click Save.

Stay up to date. Etch won’t update a pasted component for you. Subscribe and get one email when a new version is out.

Free on unlimited personal, client and commercial sites. Modify it however you like.License: FSL-1.1-MIT
Version
1.0.0-beta.4Changelog
Options
22 settings+ 37 CSS variablesSee all
Tested on Etch
1.8.0
Tested on WordPress
7.1.4
Live demo

11 examples in real layouts

Click Read more, use Tab and Enter, or try Expand all in the FAQ. Mobile switches the frame to phone width, where one more example collapses.

Live
  • Instances: 16
  • Content: Text, Nested elements
  • Buttons: Outline, Text only
  • Triggers: Expand all, Collapse all
Open in a new tab
Features

What it does

One pasted component with its own CSS and script. There is no library behind it and nothing loads from a CDN.

  • A button only when it’s needed

    The button shows up only when the content is taller than the collapsed height plus a small margin. It measures again when the width, fonts, images or content change, so short text never gets a pointless toggle.

  • Text or nested elements

    Show the Text prop with its line breaks, including dynamic data such as an excerpt. Or switch to Nested elements and put headings, images, lists, tables and other components into the slot.

  • Any CSS height

    Use 12rem, 180px, clamp() or 4lh for about four lines. A CSS variable can set none in a media query, so the content collapses on phones and shows in full on wider screens.

  • A fade for any background

    The fade is a transparency mask, so it blends into a flat color, a gradient or a photo, and there is no color to match. Two props set where it starts and ends.

  • Accessible by default

    A native button with aria-expanded and aria-controls and a focus ring in the text color. Keyboard focus that lands in clipped content opens it. Checked with NVDA, VoiceOver and TalkBack.

  • 37 styling variables

    Colors, fonts, the button frame, hover, focus, the icon and the motion, set on any parent class. Button style switches to Text only. ACSS 4 tokens with plain fallbacks, so it also works without Automatic.css.

  • Control it with or without code

    Command events expand, collapse or refresh one instance, a section or the whole page. A button or link with two data attributes does the same with no code at all, for example Expand all in a FAQ.

  • Ready for loops and AJAX

    Each instance keeps its own state and IDs, so it works in Etch loops. Instances that arrive later by AJAX, for example from a Load more button, start within a frame.

Install

Add it in four steps

The CSS and the script travel inside the component, so there is no plugin to install and no library to load. It works with or without Automatic.css 4.

Shows without its styles? It was pasted but not saved, and pasting again won’t repair it. Delete ED Read More from your components, paste it again and click Save.

  1. Copy the componentUse Copy component at the top of this page, or download the .json file.
  2. Paste it on the Etch canvasSelect where it should go, press Ctrl+V or ⌘V, then click Save. Etch adds the component to your list right away but stores its CSS only when you save.
  3. Add your contentReplace the sample Text, or set Content source to Nested elements and put headings, images and lists into the content slot.
  4. Set the height and the labelsChoose a Collapsed height and the button texts. Every prop edit shows in the canvas at once, without saving. The canvas keeps the content open for editing; Builder preview shows the collapsed view.
Options

22 settings in the Etch props panel

In the order of the Etch props panel, where each setting has help text too. Numbers are typed as plain text, because Etch has no number prop.

Give each button some context

Every button says Read more by default. When a page has several, fill Read more accessible label with a longer name that starts with the visible text, such as Read more about the warranty, so screen reader users can tell the buttons apart.

The canvas shows the content expanded so you can edit it. On the page, each instance follows Initial state, so a forgotten Builder preview setting never reaches your visitors.

Content

Content sourcecontentMode
Text shows the Text prop. Nested elements shows the content slot instead, for headings, images, lists, links and other components. Only the chosen source is rendered, so the page holds no hidden copy.Default: Text
Texttext
Plain text with line breaks, shown when Content source is Text. Dynamic data such as the post excerpt works too. HTML shows as text, so use Nested elements for rich text.Default: four sample paragraphs.
Collapsed heightcollapsedHeight
Any CSS length, such as 12rem, 180px, clamp() or 4lh for about four lines. A plain number means pixels, and none never collapses. Percentages are not supported.Default: calc(var(--space-xl, 4rem) * 3)
Height margin (px)heightMargin
Overflow tolerance from 0 to 10000 px. Content that is at most this much taller than the collapsed height shows in full, without a button.Default: 16

State

Initial stateinitialState
How each instance starts on the page. The builder canvas has its own setting, Builder preview.Default: Collapsed
Allow collapsing againallowCollapse
No turns the button into a one-way Show more. It disappears after expanding, and keyboard focus moves to the revealed content.Default: Yes

Animation

Animation duration (ms)duration
Height animation from 0 to 10000 ms. Empty follows the ACSS transition duration, or 0.3 s without ACSS. Reduced motion always turns the animation off.Empty by default.
Button label fade (ms)buttonFade
How long the label fades when it switches between Read more and Read less, from 0 to 2000 ms. 0 turns the fade off.Default: 120

Button text

Read more textmoreText
Visible label while the content is collapsed. Leave it empty for an icon-only button.Default: Read more
Read less textlessText
Visible label while the content is expanded. Leave it empty for an icon-only button.Default: Read less
Read more accessible labelmoreLabel
Optional longer name for screen readers, such as Read more about the warranty. The visible text stays part of the name.Empty by default.
Read less accessible labellessLabel
The same for the expanded state, such as Read less about the warranty.Empty by default.

Button look

Button stylebuttonStyle
Outline button, or Text only: no border, background or padding, an underline on hover and a click target of at least 24 × 24 px. Labels, icon and focus ring stay the same.Default: Outline button
Button alignmentalignment
Start, Center, End or Stretch. Start and End follow the writing direction.Default: Start
Iconicon
Chevron, None, or Custom slot for your own SVG or icon in the icon slot. An empty custom slot falls back to the chevron.Default: Chevron
Icon positioniconPosition
After or before the visible label.Default: After text
Expanded icon rotation (deg)iconRotation
How far the icon turns when the content is expanded, from -3600 to 3600 degrees. 45 turns a plus into a cross; 0 keeps the icon still.Default: 180

Fade

Fade gradientfade
Fades the end of the collapsed preview to transparent, so it blends into any background, from a flat color to a photo. Forced colors mode shows no fade.Default: Yes
Fade start (%)fadeStart
Where the fade begins, as a percentage of the collapsed height, from 0 to 100.Default: 60
Fade end (%)fadeEnd
Where the fade ends, between Fade start and 100.Default: 100

Scrolling and builder

Keep button in view on collapsescrollOnCollapse
After a collapse, scrolls the page only when the focused button would end up off screen.Default: Yes
Builder previewbuilderPreview
Builder only. Expanded for editing shows all the content with a dashed line where it will be cut; Collapsed preview shows the collapsed height. The page always follows Initial state.Default: Expanded for editing
Events, commands and triggers: for developers

Both events bubble from the .ed-read-more root, so one listener on document hears every instance. Commands and triggers act on the instance they target, or on every instance inside the element they target.

Events

ed-read-more:toggle
Fires on every state change: a click, Enter or Space, keyboard focus entering clipped content, a link to an #id inside it, a command or a trigger.Detail: expanded, reason
ed-read-more:complete
Fires once the height has settled: when the animation ends, or right after toggle when nothing animates. If another change starts first, only the last one completes.Detail: expanded, reason

Commands

ed-read-more:expand
Expands. Dispatch it on a root or an element inside it for that instance, on a wrapper for every instance inside, or on document for the whole page. It doesn’t need to bubble.Example: root.dispatchEvent(new Event('ed-read-more:expand'))
ed-read-more:collapse
Collapses. It also works in one-way mode, where the button then shows again. If the collapse would hide the focused element, focus moves to the button.Example: section.dispatchEvent(new Event('ed-read-more:collapse'))
ed-read-more:refresh
Measures again at once and picks up instances added since the last frame. Use it after a change the component cannot see.Example: document.dispatchEvent(new Event('ed-read-more:refresh'))

Buttons and links without code

data-ed-rm-action
Add it to any button, or to a link with href. toggle on several instances acts as a group: it collapses them when all are open and expands them otherwise.Values: expand, collapse or toggle
data-ed-rm-target
A CSS selector, such as #faq. Without it, the trigger acts on the instance it sits in. The component adds aria-controls to button triggers, and aria-expanded for toggle.Values: any CSS selector

State hooks on the root

data-ed-rm-state
The current state, for your own CSS. Content that fits counts as expanded.Values: collapsed or expanded
data-ed-rm-overflow
True when the content is taller than the collapsed height. Triggers get the same attribute, so you can hide them when nothing is long enough.Values: true or false
data-ed-rm-ready
Set once the script has measured the content.Values: true
data-ed-rm-empty-icon
True when the custom icon slot is empty, so the chevron shows.Values: true
Styling: 37 CSS variables

Set them on any parent element or class, such as a card or a section, or on :root for the whole site. They all inherit, so no extra selectors or !important are needed. The component’s own style in Etch starts with the same list as commented lines you can switch on, but a parent class is safer: it survives updates.

Content

--ed-read-more-collapsed-height
Height of the collapsed preview; it wins over the Collapsed height prop. Set none in a media query to show everything on wider screens.Default: the Collapsed height prop.
--ed-read-more-color
Text color of the content and the button.Default: inherit
--ed-read-more-font-family
Font of the content and the button.Default: inherit
--ed-read-more-text-size
Base text size of the content and the button.Default: inherit
--ed-read-more-line-height
Line height of the content; lh heights follow it. ACSS Smart Line Height is recalculated for the component’s own text size.Default: var(--text-line-height, inherit)
--ed-read-more-gap
Space between the content and the button.Default: var(--space-s, 1rem)

Button

--ed-read-more-button-font-family
Button font.Default: inherit
--ed-read-more-button-text-size
Button text size, such as var(--text-s).Default: inherit
--ed-read-more-button-font-weight
Button text weight.Default: inherit
--ed-read-more-button-line-height
Line height of a button label that wraps.Default: 1.3
--ed-read-more-button-letter-spacing
Letter spacing.Default: normal
--ed-read-more-button-text-transform
Text transform, such as uppercase.Default: none
--ed-read-more-button-text-decoration
Text decoration, such as underline for a label that is always underlined.Default: none
--ed-read-more-button-padding
Inner spacing, as padding shorthand.Default: 0.5em 0.85em
--ed-read-more-button-min-size
Minimum width and height of the click target. Keep it at 24px or more.Default: 44px
--ed-read-more-button-bg
Background.Default: transparent
--ed-read-more-button-color
Text and icon color.Default: inherit
--ed-read-more-button-border-width
Border width; 0 removes the border.Default: 1px
--ed-read-more-button-border-style
Border style.Default: solid
--ed-read-more-button-border-color
Border color.Default: currentColor
--ed-read-more-button-radius
Corner radius.Default: var(--radius, 0.25rem)
--ed-read-more-button-shadow
Box shadow.Default: none

Hover and focus

--ed-read-more-button-hover-bg
Hover background: a tint of the text color, so it also works on dark sections.Default: color-mix(in srgb, currentColor 8%, transparent)
--ed-read-more-button-hover-color
Hover text and icon color.Default: the button color.
--ed-read-more-button-hover-border-color
Hover border color.Default: the border color.
--ed-read-more-button-hover-shadow
Hover shadow.Default: the shadow.
--ed-read-more-button-hover-text-decoration
Hover text decoration.Default: the text decoration.
--ed-read-more-focus-color
Keyboard focus ring. It takes the text color, so it contrasts wherever the text does. Set var(--focus-color) for the ACSS focus color and check its contrast.Default: currentColor
--ed-read-more-focus-width
Focus ring width.Default: 3px
--ed-read-more-focus-offset
Gap between the button and its focus ring.Default: 4px

Icon

--ed-read-more-icon-size
Icon box size; the chevron and custom icons scale with it.Default: 1em
--ed-read-more-icon-gap
Space between the label and the icon.Default: var(--space-xs, 0.5rem)
--ed-read-more-icon-color
Icon color. Monochrome SVGs without their own fill take it; explicit SVG colors and images keep theirs.Default: currentColor
--ed-read-more-icon-thickness
Stroke width of the chevron.Default: 2px

Motion

--ed-read-more-transition
Button color changes and the icon rotation.Default: var(--transition, 0.2s ease)
--ed-read-more-duration
Height animation duration, such as 0.4s or 400ms. The Animation duration prop wins.Default: var(--transition-duration, 0.3s)
--ed-read-more-easing
Timing function of the height animation.Default: var(--transition-timing, ease)
Good to know

Before you place it

Details that are easy to miss when the component goes onto a real site.

  • Screen readers get the whole text. The collapsed height is visual only. Clipped content stays in the accessibility tree, so no paragraph is cut in half for screen reader users and nothing is duplicated.
  • Rich text needs Nested elements. Text mode escapes HTML, so a WYSIWYG field shows its tags. Set Content source to Nested elements and put a div with the Etch HTML element into the content slot.
  • No percentage heights. The component’s own height depends on the collapsed height, so a percentage can’t work. Use rem, px, lh, clamp() or a spacing variable.
  • Text only keeps its own frame. Button style Text only sets padding, minimum size, background, border, shadow and the hover underline on the button itself. Frame values you set on a wrapper for the outline button don’t reach it.
  • A filled button needs its own focus color. The ring takes the label color, so white text on a fill would draw a white ring. Set --ed-read-more-focus-color to the fill or a darker shade, and check 3:1 against the page.
  • Sticky header? Add scroll padding. When a collapse scrolls the button back into view, it can land under a sticky header. Set scroll-padding-top on html to the header height.
  • Find in page can’t open it. Browsers fire no event when Ctrl+F finds text under the fade, so the match stays clipped. Links to an id or a text fragment and keyboard focus do expand the content.
  • Without JavaScript, everything shows. The content shows in full and the button stays hidden. Printing also shows the full content, without the button and the fade.
  • Some content is out of scope. Fixed or sticky elements, areas that scroll on their own, autoplay media and vertical writing modes inside the content are not supported.
  • Not tested yet: VoiceOver on a physical iPhone, and JAWS. It was checked in Chrome, Firefox, Safari, Microsoft Edge and WebKit, with VoiceOver on macOS, NVDA with Chrome and Firefox, TalkBack on an Android emulator and Safari in the iOS Simulator.
License

Free to use. Not for resale.

Licensed under FSL-1.1-MIT, the Functional Source License with an MIT future license. Each version becomes MIT-licensed two years after its release.

You can
  • Use it on unlimited personal, client and commercial websites
  • Modify and adapt it however you like
  • Use it in paid design and development work for your clients
You can’t
  • Sell it, or a modified version, as a component: in a library, bundle, template kit, plugin or marketplace listing
  • Offer it in another commercial product or service that competes with it

Keep the copyright and license notices in the code, and link to this page instead of re-hosting the download, so everyone gets fixes and updates. Read the full license

Third-party code

None. This component is all my own code under FSL-1.1-MIT. It bundles no library and loads no icon font or external script.

Updates

How to update

Etch has no update button for pasted components. Pasting a newer version over an installed one changes nothing: Etch keeps the component and the CSS it already has. To update, reinstall in five steps.

  1. Note what you setWrite down the settings and slot content of each instance, and copy any CSS you changed in the component’s own styles.
  2. Delete the componentIn Etch, delete ED Read More from your components. Every instance disappears from every page that used it.
  3. Delete its stylesIn the Style Manager, search for ed-read-more and delete the 11 styles listed below. Only the first one holds CSS; the others are empty class names.
  4. Paste the new versionCopy or download the new JSON from this page, paste it on the canvas and click Save. Etch creates the component and its CSS fresh.
  5. Put your instances backInsert an instance wherever one was, re-enter its settings and slot content, and save. Reload any other open builder tab.

Styles to delete in step 3

  • .ed-read-more
  • .ed-read-more__viewport
  • .ed-read-more__content
  • .ed-read-more__slot
  • .ed-read-more__text
  • .ed-read-more__button
  • .ed-read-more__label
  • .ed-read-more__icon
  • .ed-read-more__chevron
  • .ed-read-more__custom-icon
  • .ed-read-more__measure

Trade-offs

  • Placements are not kept. Etch doesn’t link old instances to the new component, so you insert each one again and re-enter its settings.
  • Edits inside the component’s CSS are replaced. Keep overrides on a parent class with the --ed-read-more-* variables; those survive an update.
  • Skipping a step leaves a mix. Without step 2, Etch keeps the old component. Without step 3, the new version runs on the old CSS.
  • Your trigger buttons stay as they are. Expand all and Collapse all buttons with data-ed-rm-action are ordinary page elements, so an update doesn’t touch them.

Nothing to update yet. This is the first version on etchdeveloper.com. Subscribe and you’ll get one email when the next one is out.

Changelog

What changed

Versions follow semantic versioning. When an update changes how existing options behave, its entry says so.

1.0.0-beta.4Latest
  • ReleasedFirst version on etchdeveloper.com. It stays a beta until VoiceOver on a physical iPhone and JAWS are tested.
Feedback

Tell me what this component needs

A bug, a missing option, or anything that made the component awkward to use in a real build — it all belongs here. The versions above are the ones it was tested on; if yours differ, say so.