blob: b12e08eebb0bbda246ba3d885c5ec87451d7dc69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
<header><h1>contenteditable</h1></header><div class="section-content"><p>The <code>contenteditable</code> <a href="../global_attributes">global attribute</a> is an enumerated attribute indicating if the element should be editable by the user. If so, the browser modifies its widget to allow editing.</p></div>
<h2 id="try_it">Try it</h2>
<div class="section-content">
<iframe class="interactive is-tabbed-shorter-height" height="200" src="https://interactive-examples.mdn.mozilla.net/pages/tabbed/attribute-contenteditable.html" title="MDN Web Docs Interactive Example" loading="lazy"></iframe> <p>The attribute must take one of the following values:</p> <ul> <li>
<code>true</code> or an <em>empty string</em>, which indicates that the element is editable.</li> <li>
<code>false</code>, which indicates that the element is not editable.</li> <li>
<code>plaintext-only</code>, which indicates that the element's raw text is editable, but rich text formatting is disabled.</li> </ul> <p>If the attribute is given without a value, like <code><label contenteditable>Example Label</label></code>, its value is treated as an empty string.</p> <p>If this attribute is missing or its value is invalid, its value is <em>inherited</em> from its parent element: so the element is editable if its parent is editable.</p> <p>Note that although its allowed values include <code>true</code> and <code>false</code>, this attribute is an <em><a href="https://developer.mozilla.org/en-US/docs/Glossary/Enumerated">enumerated</a></em> one and not a <em>Boolean</em> one.</p> <p>You can set the color used to draw the text insertion <a href="https://developer.mozilla.org/en-US/docs/Glossary/Caret">caret</a> with the CSS <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/caret-color"><code>caret-color</code></a> property.</p> <p>Elements that are made editable, and therefore interactive, by using the <code>contenteditable</code> attribute can be focused. They participate in sequential keyboard navigation. However, elements with the <code>contenteditable</code> attribute nested within other <code>contenteditable</code> elements are not added to the tabbing sequence by default. You can add the nested <code>contenteditable</code> elements to the keyboard navigation sequence by specifying the <code>tabindex</code> value (<a href="tabindex"><code>tabindex="0"</code></a>).</p>
</div>
<h2 id="specifications">Specifications</h2>
<div class="_table"><table class="standard-table">
<thead><tr><th scope="col">Specification</th></tr></thead>
<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/interaction.html#attr-contenteditable">HTML Standard <br><small># attr-contenteditable</small></a></td></tr></tbody>
</table></div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody>
<tr>
<th><code>contenteditable</code></th>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">12</td>
<td class="bc-supports-yes">3</td>
<td class="bc-supports-yes">5.5</td>
<td class="bc-supports-yes">9</td>
<td class="bc-supports-yes">≤4</td>
<td class="bc-supports-yes">4.4</td>
<td class="bc-supports-yes">18</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">14</td>
<td class="bc-supports-yes">≤3.2</td>
<td class="bc-supports-yes">1.0</td>
</tr>
<tr>
<th><code>plaintext-only</code></th>
<td class="bc-supports-yes">51</td>
<td class="bc-supports-yes">≤79</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">38</td>
<td class="bc-supports-yes">Yes</td>
<td class="bc-supports-yes">51</td>
<td class="bc-supports-yes">51</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">41</td>
<td class="bc-supports-yes">Yes</td>
<td class="bc-supports-yes">5.0</td>
</tr>
</tbody>
</table></div>
<h2 id="see_also">See also</h2>
<div class="section-content"><ul> <li>All <a href="../global_attributes">global attributes</a>
</li> <li>
<a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/contentEditable"><code>HTMLElement.contentEditable</code></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/isContentEditable"><code>HTMLElement.isContentEditable</code></a>
</li> <li>The CSS <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/caret-color"><code>caret-color</code></a> property</li> <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event">HTMLElement <code>input</code> event</a></li> </ul></div><div class="_attribution">
<p class="_attribution-p">
© 2005–2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable</a>
</p>
</div>
|