w3c / w3c/editing

Spec: Empty addressable content fields with placeholders

Open
#528 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

caret-movement
Dominant language
HTML
Stars
202
Forks
43
PR merge metrics
No merged PRs in 30d

Description

Here's a proposal for an official recommendation (spec?) to create "empty addressable content fields with placeholders" inside a contenteditable.

Recommended markup for making an element addressable with the caret:

<div contenteditable="true">
  <p><br></p>
</div>

Why?

  • the <br> element ensures there's a single addressable caret position. If you added a zero-width-space instead, or any other character, you'd end up with two addressable caret positions.
  • most editors are already handling it this way (e.g. ProseMirror <p><br class="ProseMirror-trailingBreak"></p>

To add a placeholder, use an empty class and a placeholder attribute and CSS to display it:

<div contenteditable="true">
  <p class="empty" placeholder="Enter text"><br></p>
</div>
[contenteditable="true"] [placeholder].empty::before {
  color: #ccc;
  content: attr(placeholder);
}

Considerations:

  • In my opinion <div></div> without the <br> should not be addressable with the caret.
    • When developing editors very often those leaf-nodes become addressable accidentally. You'd have to write <div contenteditable="false"></div> to avoid that.
    • Already some browsers skip caret positions here, with keyboard movement. See #500
    • however, this may break some existing apps, that rely on <div></div> being addressable (though that doesn't work in all browsers)

Known issues (only related to placeholder rendering/behavior):

Contributor guide

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

Research direction

Start with the proposed contenteditable markup, placeholder CSS, and the linked issues #523, #501, #502, #498, and #499. Determine whether the editing task force wants a formal recommendation and resolve the stated browser and compatibility considerations; done means an agreed specification or explainer, not just an implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
html
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.