HTML | DOM Style textAlign Property
The DOM style textAlign property is pretty much similar to the text-align property in the CSS, it sets the alignment for the inner content of a block element.
We can use textAlign in two different ways, one to set the alignment, and the other to get the current alignment.
- Get the value from the current DOM object.
- Set the value of the current DOM object.
object.style.textAlign = "left | right | center | justify | initial | inherit";
- left: 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 centre, 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 Value: It returns a string value which represents the alignment of the text inside the element.
- Before set align property:
- After set align property:
Supported Browsers: The browser supported by HTML | DOM Style textAlign Property are listed below:
- Google Chrome
- Internet Explorer
- Mozilla Firefox
My Personal Notes arrow_drop_up
Please Login to comment...