Captions may contain deliberate newlines from an editor. A whitespace rule can preserve them without injecting HTML into the component.
Worked example
// components/LinePreservingCaption.tsx
export default function LinePreservingCaption({
text = "Studio notes from the harbour",
}: { text?: string } = {}) {
return <p style={{ whiteSpace: "pre-line", overflowWrap: "anywhere" }}>{text}</p>;
}Implementation notes
React treats interpolated strings as text. Keeping line preservation in CSS avoids turning a caption editor into an HTML editor.
Try it yourself
Pass literal angle brackets and several consecutive newlines.
Open the React example →Editorial date April 15, 2026 · Published December 6, 2026