Scenario

Image resizing in contenteditable is limited or inconsistent

Resizing images within contenteditable elements is limited or behaves inconsistently across browsers. Some browsers support native resize handles, while others require manual implementation. The resize behavior may also affect the DOM structure unexpectedly.

formatting
Scenario ID
scenario-image-resize

Details

Resizing images within contenteditable elements is limited or behaves inconsistently across browsers. Some browsers support native resize handles, while others require manual implementation. The resize behavior may also affect the DOM structure unexpectedly.

Observed Behavior

Scenario 1: Native resize handles

  • Chrome/Edge: May show resize handles on selected images, but behavior inconsistent
  • Firefox: Limited or no native resize support
  • Safari: May have different resize behavior

Scenario 2: Resizing via CSS

  • Chrome/Edge: Width/height attributes may be added or removed during resize
  • Firefox: Similar behavior
  • Safari: May handle attributes differently

Scenario 3: Aspect ratio preservation

  • Chrome/Edge: May or may not preserve aspect ratio
  • Firefox: Behavior varies
  • Safari: May have different aspect ratio handling

Scenario 4: Resize events and DOM changes

  • Chrome/Edge: Resize may trigger unexpected DOM mutations
  • Firefox: Similar issues
  • Safari: May have different mutation behavior

Impact

  • Difficulty implementing consistent image resizing
  • Unexpected DOM structure changes
  • Loss of image attributes during resize
  • Need for custom resize implementation

Browser Comparison

  • Chrome/Edge: Some native support but inconsistent
  • Firefox: Limited native support
  • Safari: Different behavior, may require custom implementation

Workaround

Implement custom resize handles:

function addResizeHandles(img) {
  const handle = document.createElement('div');
  handle.className = 'resize-handle';
  handle.style.cssText = `
    position: absolute;
    width: 10px;
    height: 10px;
    background: blue;
    cursor: se-resize;
    bottom: 0;
    right: 0;
  `;
  
  let isResizing = false;
  let startX, startY, startWidth, startHeight;
  
  handle.addEventListener('mousedown', (e) => {
    isResizing = true;
    startX = e.clientX;
    startY = e.clientY;
    startWidth = img.offsetWidth;
    startHeight = img.offsetHeight;
    e.preventDefault();
  });
  
  document.addEventListener('mousemove', (e) => {
    if (!isResizing) return;
    
    const deltaX = e.clientX - startX;
    const deltaY = e.clientY - startY;
    
    img.style.width = (startWidth + deltaX) + 'px';
    img.style.height = (startHeight + deltaY) + 'px';
  });
  
  document.addEventListener('mouseup', () => {
    isResizing = false;
  });
  
  // Position handle relative to image
  const wrapper = document.createElement('div');
  wrapper.style.position = 'relative';
  wrapper.style.display = 'inline-block';
  img.parentNode.insertBefore(wrapper, img);
  wrapper.appendChild(img);
  wrapper.appendChild(handle);
}

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-0109-image-resize-limited Windows 11 Desktop or Laptop Any Chrome 120.0 US draft
ce-0139-image-resize-aspect-ratio Windows 11 Desktop or Laptop Any Chrome 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: image

Image deletion behavior varies across browsers

Deleting images from contenteditable elements behaves differently across browsers. Some browsers delete the image cleanly, while others may leave empty elements, break the DOM structure, or require multiple delete operations.

3 cases
Tags: image

Image insertion behavior varies across browsers

When inserting images into contenteditable elements, the behavior varies significantly across browsers. Images may be inserted as <img> tags, as base64 data URLs, or may not be supported at all. The size, positioning, and editing behavior also differs.

2 cases
Category: formatting

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
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.