Scenario

Font size changes behave inconsistently

Changing font size in contenteditable elements behaves inconsistently across browsers. Font sizes may be applied as inline styles, as font tags, or may not persist when typing new text. The unit (px, em, rem) handling also varies.

formatting
Scenario ID
scenario-font-size-change

Details

Changing font size in contenteditable elements behaves inconsistently across browsers. Font sizes may be applied as inline styles, as font tags, or may not persist when typing new text. The unit (px, em, rem) handling also varies.

Observed Behavior

Scenario 1: Applying font size to selected text

  • Chrome/Edge: Applies font-size as inline style, may use px units
  • Firefox: Similar behavior but unit handling may differ
  • Safari: May apply size differently or use different units

Scenario 2: Typing after applying font size

  • Chrome/Edge: New text may inherit size or use default
  • Firefox: Size may not persist for new text
  • Safari: Behavior inconsistent

Scenario 3: Relative vs absolute units

  • Chrome/Edge: May convert relative units (em, rem) to absolute (px)
  • Firefox: May preserve or convert units
  • Safari: Unit handling varies

Scenario 4: Removing font size

  • Chrome/Edge: May leave empty style attributes
  • Firefox: Similar behavior
  • Safari: May handle removal differently

Impact

  • Inconsistent font size application
  • Size formatting may not persist
  • Unit conversion issues
  • Empty style attributes in DOM

Browser Comparison

  • Chrome/Edge: Generally better size handling
  • Firefox: Size persistence may be less reliable
  • Safari: Most inconsistent behavior

Workaround

Implement custom font size handling:

element.addEventListener('beforeinput', (e) => {
  if (e.inputType === 'formatFontSize') {
    e.preventDefault();
    const selection = window.getSelection();
    if (selection.rangeCount === 0) return;
    
    const range = selection.getRangeAt(0);
    const fontSize = e.data || prompt('Enter font size (e.g., 16px, 1.2em):');
    
    if (fontSize) {
      if (range.collapsed) {
        // Set size for future typing
        const span = document.createElement('span');
        span.style.fontSize = fontSize;
        range.insertNode(span);
        range.setStart(span, 0);
        range.collapse(true);
      } else {
        // Apply size to selected text
        const span = document.createElement('span');
        span.style.fontSize = fontSize;
        try {
          range.surroundContents(span);
        } catch (e) {
          const contents = range.extractContents();
          span.appendChild(contents);
          range.insertNode(span);
        }
      }
      
      selection.removeAllRanges();
      selection.addRange(range);
    }
  }
});

References

Scenario flow

Visual view of how this scenario connects to its concrete cases and environments. Nodes can be dragged and clicked.

React Flow mini map

Variants

Each row is a concrete case for this scenario, with a dedicated document and playground.

Case OS Device Browser Keyboard Status
ce-0119-font-size-persistence-safari macOS 14.0 Desktop or Laptop Any Safari 17.0 US draft
ce-0144-font-size-unit-conversion Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0166-font-size-persistence-edge Windows 11 Desktop or Laptop Any Edge 120.0 US draft

Browser compatibility

This matrix shows which browser and OS combinations have documented cases for this scenario. Click on a cell to view the specific case.

Confirmed
Draft
No case documented

Cases

Open a case to see the detailed description and its dedicated playground.

Related Scenarios

Other scenarios that share similar tags or category.

Tags: font, typography, css

Font family changes behave inconsistently

Changing font family in contenteditable elements behaves inconsistently across browsers. The font-family CSS property may be applied inline, as a style attribute, or may not be applied at all. The behavior also varies when editing text after applying a font.

3 cases
Tags: css

Background color changes behave inconsistently

Changing background color (highlighting) in contenteditable elements behaves inconsistently across browsers. Background colors may be applied as inline styles, may not persist when typing, or may interfere with text selection. The behavior differs from text color changes.

3 cases
Tags: css

Text color changes behave inconsistently

Changing text color in contenteditable elements behaves inconsistently across browsers. Colors may be applied as inline styles, as font tags, or may not persist when typing. The color format (hex, rgb, named colors) handling also varies.

2 cases
Category: formatting

Blockquote editing behavior varies across browsers

Editing text within blockquote elements in contenteditable behaves inconsistently across browsers. Pressing Enter, applying formatting, or pasting content may break the blockquote structure, create nested blockquotes, or behave unexpectedly.

4 cases
Category: formatting

Browser auto-formatting interferes with contenteditable editing

Browsers may automatically format text in contenteditable elements, such as converting URLs to links, capitalizing text, formatting numbers, or applying other transformations. This auto-formatting can interfere with editing, cause cursor positioning issues, and create unwanted markup or style changes.

0 cases

Comments & Discussion

Have questions, suggestions, or want to share your experience? Join the discussion below.