[Feature request] Vertical spacing (margins) for headings and lists in htmlStyle

Open
#832 1 comment 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 4 days

@henrikra is already working on this.

Since Oct 23, 2026.

  • #838 by @henrikra — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
20/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
android, css, ios, react-native
Domain
frontend, mobile

Research direction

The request covers htmlStyle rendering in EnrichedTextInput and EnrichedText on iOS, Android, and web; an open linked pull request (#838) is already addressing it. For context, compare the sibling library's ParagraphStyleUtils.m and MarginBottomSpan.kt, linked in the issue, and review the proposed examples and platform behaviors. Done means block margins work across platforms while leaving HTML, plain text, and selection offsets unchanged.

Written by the indexing model from the issue text.

Description

enhancement

Is your feature request related to a problem? Please describe.

This is the separate request @kacperzolkiewski asked for in #259: a way to add vertical space around block elements.

We render the same HTML with EnrichedTextInput on web and on native. On web we style it with CSS: margin: 18px 0 8px on h1–h3, margin: 6px 0 on ul/ol, and line-height: 1.55. On native we can match the line height with the lineHeight style, and soon on EnrichedText too (#724). But we can't add space above or below headings or lists. HeadingStyle only has fontSize and bold, on main as well.

As a result, headings sit flush against the paragraph before and after them. Long documents read as one dense block on phones, while the same document looks well spaced on web. Our users reported exactly this.

Describe the solution you'd like

Per-block vertical spacing in htmlStyle, for both EnrichedTextInput and EnrichedText:

htmlStyle={{
  h2: { fontSize: 20, bold: true, marginTop: 18, marginBottom: 8 },
  ul: { gapWidth: 8, marginLeft: 20, marginTop: 6, marginBottom: 6 },
}}
  • iOS: paragraphSpacingBefore on a block's first paragraph and paragraphSpacing on its last.
  • Android: a span that adds top and bottom space.
  • Web: CSS margins.

The spacing should be visual only, with no change to the HTML, the plain text or selection offsets. #470 (paragraphSpacing for checkbox lists) is a similar idea for one block type.

The sibling library react-native-enriched-markdown already ships this API in its renderer: markdownStyle.h1–h6 take marginTop and marginBottom (docs).

Matching those prop names and behaviours here would keep the two libraries consistent. One difference for an editor: the space above a block should come from paragraphSpacingBefore rather than an inserted spacer character, so the text and offsets stay unchanged.

Describe alternatives you've considered

  • Inserting <br> around headings before rendering: the editor then saves those <br>s back into the document.
  • A large lineHeight: it spreads out every line, not just the gaps between blocks (as noted in #259).

Additional context

react-native-enriched-html 1.1.1, React Native 0.86.3, Expo SDK 57, tested on the iOS 18.6 simulator.

Dominant language
C
Stars
1.4k
Forks
77
Avg merge
3d 14h
Merged PRs (30d)
24

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from software-mansion/react-native-enriched-html

All issues in software-mansion/react-native-enriched-html

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.