GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • MDN
  • HTML: Markup language
  • Elements
  • Global attributes
  • Attributes
  • See all…
  • Responsive images
  • HTML cheatsheet
  • Date & time formats
  • See all…
  • SVG
  • MathML
  • XML
  • CSS: Styling language

This view

  • Original page
  • New address

GeezerVison is showing developer.mozilla.org — TextFormat - Web APIs | MDN

TextFormat

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Want more browser support for this feature? Tell us why.

  • See full compatibility
  • Learn more

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The TextFormat interface represents specific formatting that should be applied to a range of text in an editable text region that's attached to an EditContext instance. The text formatting is requested by the Input Method Editor (IME) window that the user is composing text with.

When using one of the default editable regions of the web, such as a <textarea> element, IME composition is handled by the browser and operating system for you. For example, when using Japanese IME in a textarea, on Windows, the following text formats can be applied:

  • When text is being composed with the keyboard, the typed characters have a thin wavy underline:

    A textarea in Microsoft Edge on Windows with some Japanese text being composed from the IME window

  • When the user selects a suggestion from the list of candidates in the IME window, the text is replaced and is underlined with a thick solid line:

    A textarea in Microsoft Edge on Windows with some Japanese text being selected from the IME window

When creating your own custom editable region by using the EditContext API, you need to handle IME composition yourself. You should listen for the textformatupdate event, which gives you the list of text formats that the IME window wants to apply to the text being composed. You should then update the formatting of the text displayed in your editable region accordingly.

Constructor

TextFormat()

Returns a new TextFormat instance.

Instance properties

TextFormat.rangeStart Read only

The start position of the text range that needs to be formatted with the given text format.

TextFormat.rangeEnd Read only

The end position of the text range that needs to be formatted with the given text format.

TextFormat.underlineStyle Read only

The style of the underline that needs to be applied to the text range that is being formatted.

TextFormat.underlineThickness Read only

The thickness of the underline that needs to be applied to the text range that is being formatted.

Examples

Using the textformatupdate event

In the following example, the textformatupdate event is used to log the various formats that the IME composition window wants to apply to text ranges in the editable element. Note that the event listener callback in this example is only called when using an IME window to compose text.

html
<div id="editor"></div>
#editor {
  height: 200px;
  background: #eeeeee;
}
js
const editorEl = document.getElementById("editor");
const editContext = new EditContext(editorEl);
editorEl.editContext = editContext;

editContext.addEventListener("textformatupdate", (e) => {
  // Get the TextFormat instances.
  const formats = e.getTextFormats();

  // Iterate over the TextFormat instances.
  for (const format of formats) {
    console.log(
      `Applying a ${format.underlineThickness} ${format.underlineStyle} underline between ${format.rangeStart} and ${format.rangeEnd}.`,
    );
  }
});

Specifications

Specification
EditContext API
# dom-textformat

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on Aug 12, 2025 by MDN contributors.

View this page on GitHub • Report a problem with this content
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.