Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

JavaScript Dictionary

  1. Home
  2. JavaScript Dictionary
  3. HTML Element .innerText

HTML Element .innerText Since: HTML5(IE origin → standardized)

A property that gets or sets the visible text of an HTML element. Text hidden via CSS is not included, so it only reflects what is actually displayed on screen.

Syntax

// Get the visible text.
var text = element.innerText;

// Set the text.
element.innerText = "New text";

Sample Code

<div id="box">
	<p>Visible text</p>
	<p style="display: none;">Hidden text</p>
	<span>Another text</span>
</div>
var box = document.querySelector("#box");

// innerText only retrieves text that is currently visible on screen.
console.log(box.innerText);
// Returns "Visible text" and "Another text".
// Hidden text is not included.

// textContent retrieves all text regardless of CSS visibility.
console.log(box.textContent);
// Returns "Visible text", "Hidden text", and "Another text".

// Setting the text replaces all child elements.
box.innerText = "New text";

Difference Between innerText and textContent

PropertyDescription
innerTextReturns only the text that is visible on screen. Text hidden via CSS is excluded, and line breaks reflect <br> tags and block element boundaries. Triggers a layout recalculation, which may affect performance.
textContentReturns the content of all text nodes regardless of CSS visibility. Whitespace and line breaks are preserved as they appear in the HTML source. Does not trigger a layout recalculation, so it is faster.

Overview

element.innerText is a property that gets or sets the visible text of an HTML element. It is similar to element.textContent, but unlike textContent, innerText excludes text from elements hidden via CSS and returns only what is actually rendered on screen.

element.innerText accesses layout information, causing the browser to recalculate the layout each time it is called. Calling it repeatedly on many elements inside a loop may degrade performance. If you do not need to account for visibility, using element.textContent is more efficient.

When setting text, both element.innerText and element.textContent replace all existing child elements with a text node. HTML tags are treated as literal strings and are not parsed as markup. If you need the value to be interpreted as HTML, use element.innerHTML instead.

Browser Compatibility

Chrome Chrome
49+
Supported in all versions
Firefox Firefox
57+
44 or earlier ×
Safari Safari
18+
Supported in all versions
Edge Edge
80+
11 or earlier ×
IE IE
11+
4.5 or earlier ×
Opera Opera
48+
9 or earlier ×
iOS Safari iOS Safari
18+
Supported in all versions
Android Browser Android Browser
37+
Supported in all versions
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
44 or earlier ×

If you find any errors or copyright issues, please .