HTML DOM Style textAlign Property Last Updated : 22 Apr, 2024 Comments Improve Suggest changes Like Article Like Report The HTML DOM style textAlign property is similar to the text-align property in the CSS. It sets the alignment for the inner content of a block element using HTML DOM. SyntaxWe can use textAlign in two different ways, one to set the alignment, and the other to get the current alignment. Get the value of textAlign from the current DOM object. object.style.textAlignSet the value of textAlign to the current DOM object.object.style.textAlign = "left | right | center | justify | initial | inherit";Property Valuesleft: It is the default value. The content gets aligned to the left side.right: The content gets aligned to the right side.center: This sets the content to the center, between the left and right edges.justify: This introduces additional spaces between the words such that the very first word of the line gets aligned to the left side and the last word to the right.inherit: It does not do anything fancy rather it sets the value exactly the same as of its immediate parent.Return ValueIt returns a string value which represents the alignment of the text inside the element. Example: In this example, we will set the text alignment using HTML DOM textAlign property. HTML <!DOCTYPE html> <html> <head> <title> HTML DOM Style textAlign Property </title> <style> h2 { text-align: center; } #container { border: 1px solid black; background-color: #e1e1e1; padding: 20px; width: 400px; margin: auto; } #controls { text-align: center; margin-top: 25px; } </style> </head> <body> <h2>HTML DOM Style textAlign Property</h2> <div id="container"> <p id="content"> An operating system acts as an intermediary between the user of a computer and computer hardware. The purpose of an operating system is to provide an environment in which a user can execute programs in a convenient and efficient manner. An operating system is software that manages the computer hardware. The hardware must provide appropriate mechanisms to ensure the correct operation of the computer system and to prevent user programs from interfering with the proper operation of the system. </p> </div> <div id="controls"> <label>Set Alignment: </label> <select id="alignment"> <option value="left" default>Left</option> <option value="right">Right</option> <option value="center">Center</option> <option value="justify">Justify</option> </select> <button id="do-align"> Set Align Property </button> </div> <script> // Collecting elements let inside_content = document.getElementById("content"); let align_option = document.getElementById("alignment"); let align_btn = document.getElementById("do-align"); // Adding an event to the button align_btn.onclick = function () { // Get current value from the dropdown let align_val = align_option.options[align_option.selectedIndex].value; // Set this value to alignment of the content inside_content.style.textAlign = align_val; } </script> </body> </html> Output: Supported BrowsersGoogle ChromeInternet ExplorerMozilla FirefoxOperaSafari Comment More infoAdvertise with us Next Article HTML | DOM Input Range Object F feduser Follow Improve Article Tags : JavaScript HTML-DOM Similar Reads HTML | DOM ClipboardEvent The ClipboardEvent refers to all the events which occur when the clipboard is modified. All the properties and methods are inherited from the âEvent Objectâ. There are 3 main ClipboardEvents:oncopyoncutonpasteReturn Value: It returns an object containing the data affected by the clipboard operation. 1 min read HTML | DOM Input Range Object The Input Range Object in HTML DOM is used to represent the HTML < input > element with type="range". This object is used to access or create the <input> element. This element can be accessed by using getElementById() method. Syntax: document.getElementById("Input_ID"); This Input_ID is 2 min read HTML | DOM Window closed Property The Window closed property in HTML DOM is used to return a value that indicates whether the referred window is closed or not. Syntax: window.close() Return Value: A Boolean value, true if window is closed otherwise false. Example: HTML <!DOCTYPE html> <html> <head> <title> HT 1 min read HTML | DOM Style textAlignLast Property The Style textAlignLast property in HTML DOM is used to set the alignment of the last line of the text. Syntax: Return the textAlignLast property: object.style.textAlignLast Set the textAlignLast property: object.style.textAlignLast = "auto | left | right | center | justify | start | end | initial | 2 min read HTML | DOM TouchEvent When a user touches a touch-based device the resulted events are handled by TouchEvent Object. The touch events consist of three types of interfaces i.e. Touch, TouchEvent and TouchList. The single contact point events on a touch-sensitive device are handled by the Touch interface. The events which 2 min read HTML | DOM Storage Event The Storage Event in HTML DOM is used to make change in the storage area in the context of another document. When there is modification in the storage area of the window, a storage event is sent to that window. Syntax: window.addEventListener("storage", script) Example: html <!DOCTYPE html> 1 min read HTML | DOM PageTransitionEvent The PageTrasitionEvent occurs during the time a document is being loaded or unloaded. Syntax: PageTransitionEvent.persisted Property Values: persisted: Returns boolean value whether the webpage was cached or not. Return Value: This property returns True if the document is loaded from a cache or not 1 min read HTML DOM Style display Property The HTML DOM Style display property is used to set or return the display type of an element. It is similar to the visibility property, which displays or hides the element. With a slight difference in display: none, hiding the entire element, while visibility: hidden meaning only the contents of the 3 min read HTML | DOM Input Submit Object The Input Submit object in HTML DOM represents the HTML <input> element with type = "submit" attribute. Syntax: It creates an Input Submit Object.document.createElement("INPUT")It is used to access an Input Submit Object.document.getElementById("id") Property Values: autofocus: It sets or retu 3 min read HTML | DOM Input URL Object The Input URL object in HTML DOM represents an <input> element with type = "url" attribute. The element with type url can be accessed by using getElementById() method. Syntax: document.getElementById("id"); where id is assigned to the <input> tag. Property Values: list: It returns the re 3 min read Like