JavaScriptMedium
What is the difference between innerHTML and textContent?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
innerHTML and textContent are both properties used to get or set the content of an HTML element, but they serve different purposes. innerHTML returns or sets the HTML markup contained within the element, which means it can parse and render HTML tags. On the other hand, textContent returns or sets the text content of the element, ignoring any HTML tags and rendering them as plain text.
js
// Example of innerHTML
element.innerHTML = "<strong>Bold Text</strong>"; // Renders as bold text
// Example of textContent
element.textContent = "<strong>Bold Text</strong>"; // Renders as plain text: <strong>Bold Text</strong>
