Home >Web Front-end >HTML Tutorial >How to align text in html
The following methods can be used to align text in HTML: Tag method: "align" attribute (left/center/right) Attribute method: "text-align" attribute (left/center/right)
How to align text in HTML
In HTML, you can align text by using the following tags and attributes:
Tag method:
:
Left aligned text
:
Center the text
:
Right aligned text
Attribute method:
Left aligned text
Center aligned text
Align text right
To left-align a section of text, you can use the following code:
<code class="html"><p align="left">这是左对齐的文本</p></code>
To center align a section of text, you can use the following code:
<code class="html"><p align="center">这是居中对齐的文本</p></code>
To right align a section of text, you can use the following code:
<code class="html"><p align="right">这是右对齐的文本</p></code>Note:
The
<div>
or <h1>
.
If both label alignment and attribute alignment are set on the element, attribute alignment takes precedence.
The above is the detailed content of How to align text in html. For more information, please follow other related articles on the PHP Chinese website!