Phenomenon
When applying multiple formatting operations (bold, italic, underline) to text, deeply nested HTML structures are created (e.g., <b><i><u>text</u></i></b>). This makes the DOM complex and hard to manage.
Reproduction example
- Select some text
- Apply bold formatting
- Apply italic formatting
- Apply underline formatting
- Observe the DOM structure
Observed behavior
- Deeply nested structure:
<b><i><u>text</u></i></b> - Or different nesting order depending on application sequence
- DOM becomes complex and bloated
- Difficult to manage formatting state
Expected behavior
- Formatting should be applied efficiently
- Nesting should be minimized where possible
- Structure should be normalized
- Formatting state should be easy to query
Browser Comparison
- Chrome/Edge: Creates nested structures (this case)
- Firefox: Similar nesting behavior
- Safari: Most complex nesting
Notes and possible direction for workarounds
- Normalize formatting structure after operations
- Merge same-type formatting elements
- Use consistent nesting order
- Consider using data attributes instead of nested elements