Open In App
Related Articles

Difference between innerText and innerHTML

Improve Article
Save Article
Like Article

innerText and innerHTML are both properties of JavaScript. However, there are differences in which the text is handled. Let us check the syntax of the two and then take an example to look at the differences. 


Let us assume that we have a JavaScript variable called x.

let x = document.getElementById('test');
  • innerText
  • innerHTML



<!DOCTYPE html>
        Difference between
        InnerHTML and InnerText
<body style="text-align:center;">
    <h1 style="color:green">GeeksforGeeks</h1>
    <div id="test">
        The following element contains some
        <codes>code</codes> and
        <italic>some text</italic>.
    <button onClick="innerHTMLFn()">
    <button onClick="innerTextFn()">
    <p id="op"></p>
        function innerTextFn() {
            let x = document.getElementById('test');
        function innerHTMLFn() {
            let x = document.getElementById('test');




As we can see from the example above the innerText property sets or returns the text content as plain text of the specified node, and all its descendants whereas the innerHTML property gets and sets the plain text or HTML contents in the elements. Unlike innerText, inner HTML lets you work with HTML rich text and doesn’t automatically encode and decode text.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 31 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials