Menu
×
   ❮     
HTMLCSSJAVASCRIPTSQLPYTHONJAVAPHPHOW TOW3.CSSCC++C#BOOTSTRAPREACTMYSQLJQUERYEXCELXMLDJANGONUMPYPANDASNODEJSDSATYPESCRIPTANGULARGITPOSTGRESQLMONGODBASPAIRGOKOTLINSASSVUEGEN AISCIPYCYBERSECURITYDATA SCIENCEINTRO TO PROGRAMMINGBASH

JS Reference

JS by CategoryJS by Alphabet

JavaScript

JS ArraysJS BooleanJS ClassesJS DatesJS ErrorJS GlobalJS JSONJS MapsJS MathJS NumbersJS ObjectsJS OperatorsJS PrecedenceJS PromisesJS RegExpJS SetsJS StatementsJS StringsJS TypedArray

Window

Window ObjectWindow ConsoleWindow HistoryWindow LocationWindow NavigatorWindow Screen

HTML DOM

HTML DocumentsHTML ElementsHTML AttributesHTML CollectionHTML NodeListHTML DOMTokenListHTML Styles
alignContentalignItemsalignSelfanimationanimationDelayanimationDirectionanimationDurationanimationFillModeanimationIterationCountanimationNameanimationTimingFunctionanimationPlayStatebackgroundbackgroundAttachmentbackgroundClipbackgroundColorbackgroundImagebackgroundOriginbackgroundPositionbackgroundRepeatbackgroundSizebackfaceVisibilityborderborderBottomborderBottomColorborderBottomLeftRadiusborderBottomRightRadiusborderBottomStyleborderBottomWidthborderCollapseborderColorborderImageborderImageOutsetborderImageRepeatborderImageSliceborderImageSourceborderImageWidthborderLeftborderLeftColorborderLeftStyleborderLeftWidthborderRadiusborderRightborderRightColorborderRightStyleborderRightWidthborderSpacingborderStyleborderTopborderTopColorborderTopLeftRadiusborderTopRightRadiusborderTopStyleborderTopWidthborderWidthbottomboxShadowboxSizingcaptionSidecaretColorclearclipcolorcolumnCountcolumnFillcolumnGapcolumnRulecolumnRuleColorcolumnRuleStylecolumnRuleWidthcolumnscolumnSpancolumnWidthcounterIncrementcounterResetcssFloatcursordirectiondisplayemptyCellsfilterflexflexBasisflexDirectionflexFlowflexGrowflexShrinkflexWrapfontfontFamilyfontSizefontStylefontVariantfontWeightfontSizeAdjustheightisolationjustifyContentleftletterSpacinglineHeightlistStylelistStyleImagelistStylePositionlistStyleTypemarginmarginBottommarginLeftmarginRightmarginTopmaxHeightmaxWidthminHeightminWidthobjectFitobjectPositionopacityorderorphansoutlineoutlineColoroutlineOffsetoutlineStyleoutlineWidthoverflowoverflowXoverflowYpaddingpaddingBottompaddingLeftpaddingRightpaddingToppageBreakAfterpageBreakBeforepageBreakInsideperspectiveperspectiveOriginpositionquotesresizerightscrollBehaviortableLayouttabSizetextAligntextAlignLasttextDecorationtextDecorationColortextDecorationLinetextDecorationStyletextIndenttextOverflowtextShadowtextTransformtoptransformtransformOrigintransformStyletransitiontransitionPropertytransitionDurationtransitionTimingFunctiontransitionDelayunicodeBidiuserSelectverticalAlignvisibilitywidthwordBreakwordSpacingwordWrapwidowszIndex

HTML Events

HTML EventsHTML Event ObjectsHTML Event PropertiesHTML Event Methods

Web APIs

API CanvasAPI ConsoleAPI FetchAPI FullscreenAPI GeolocationAPI HistoryAPI MediaQueryListAPI StorageAPI ValidationAPI Web

HTML Objects

<a><abbr><address><area><article><aside><audio><b><base><bdo><blockquote><body><br><button><canvas><caption><cite><code><col><colgroup><datalist><dd><del><details><dfn><dialog><div><dl><dt><em><embed><fieldset><figcaption><figure><footer><form><head><header><h1> - <h6><hr><html><i><iframe><img><ins><input> button<input> checkbox<input> color<input> date<input> datetime<input> datetime-local<input> email<input> file<input> hidden<input> image<input> month<input> number<input> password<input> radio<input> range<input> reset<input> search<input> submit<input> text<input> time<input> url<input> week<kbd><label><legend><li><link><map><mark><menu><menuitem><meta><meter><nav><object><ol><optgroup><option><output><p><param><pre><progress><q><s><samp><script><section><select><small><source><span><strong><style><sub><summary><sup><table><tbody><td><tfoot><th><thead><tr><textarea><time><title><track><u><ul><var><video>

Other References

CSSStyleDeclarationJS Conversion


HTML DOM Element innerHTML

Example

Get the HTML content of an element with id="myP":

let html = document.getElementById("myP").innerHTML;
Try it Yourself »

Change the HTML content of an element with id="demo":

document.getElementById("demo").innerHTML = "I have changed!";
Try it Yourself »

Get the HTML content of a <ul> element with id="myList":

let html = document.getElementById("myList").innerHTML;
Try it Yourself »

Delete the HTML content of a <p> element with id="demo":

element.innerHTML = "";
Try it Yourself »

More examples below.


Description

The innerHTML property sets or returns the HTML content (inner HTML) of an element.

The Differences Between
innerHTML, innerText and textContent

See below


Syntax

Return the innerHTML property:

element.innerHTML

Set the innerHTML property:

element.innerHTML = text

Property Value

PropertyDescription
StringHTML content.

Return Value

TypeDescription
StringThe HTML content of the element.


More Examples

Example

Change the HTML content of two elements:

let text = "Hello Dolly.";
document.getElementById("myP").innerHTML = text;
document.getElementById("myDIV").innerHTML = text;
Try it Yourself »

Example

Repeat the HTML content of an element:

element.innerHTML += element.innerHTML;
Try it Yourself »

Example

Change the HTML content and URL of a link:

element.innerHTML = "W3Schools";
element.href = "https://www.w3schools.com";
Try it Yourself »

The Differences Between
innerHTML, innerText and textContent

The innerHTML property returns:
The text content of the element, including all spacing and inner HTML tags.
The innerText property returns:
Just the text content of the element and all its children, without CSS hidden text spacing and tags, except <script> and <style> elements.
The textContent property returns:
The text content of the element and all descendaces, with spacing and CSS hidden text, but without tags.

HTML Example

<p id="myP">   This element has extra spacing     and contains <span>a span element</span>.</p>

JavaScript Examples

let text = document.getElementById("myP").innerText;

let text = document.getElementById("myP").innerHTML;

let text = document.getElementById("demo").textContent;
Try it Yourself »

In the example above:

The innerText property returns:
This element has extra spacing and contains a span element.
The innerHTML property returns:
   This element has extra spacing    and contains <span>a span element</span>.
The textContent property returns:
   This element has extra spacing    and contains a span element.

Browser Support

element.innerHTML is supported in all browsers:

ChromeEdgeFirefoxSafariOperaIE
YesYesYesYesYesYes

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

close