Align the Text in Markdown Files and Web Pages

Apr. 21, 2024

In Markdown files and web page, we can use <p> element and its style attribute to realize aligning the text, center, left, and right. For example,

1
<p style="text-align:center;">Ignorance is bliss.</p>

Ignorance is bliss.

1
<p style="text-align:left;">Ignorance is bliss.</p>

Ignorance is bliss.

1
<p style="text-align:right;">Ignorance is bliss.</p>

Ignorance is bliss.


This method is also suitable for multiple lines text, as long as using <br> to make a break:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<p style="text-align:center;">No man is an island,<br>
Entire of itself;<br>
Every man is a piece of the continent,<br>
A part of the main.<br><br>
If a clod be washed away by the sea,<br>
Europe is the less,<br>
As well as if a promontory were:<br>
As well as if a manor of thy friend's<br>
Or of thine own were.<br><br>
Any man's death diminishes me,<br>
Because I am involved in mankind.<br>
And therefore never send to know for whom the bell tolls;<br>
It tolls for thee.<br>
<br>
by John Donne <br>
</p>

No man is an island,
Entire of itself;
Every man is a piece of the continent,
A part of the main.

If a clod be washed away by the sea,
Europe is the less,
As well as if a promontory were:
As well as if a manor of thy friend's
Or of thine own were.

Any man's death diminishes me,
Because I am involved in mankind.
And therefore never send to know for whom the bell tolls;
It tolls for thee.

by John Donne

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<p style="text-align:left;">No man is an island,<br>
Entire of itself;<br>
Every man is a piece of the continent,<br>
A part of the main.<br><br>
If a clod be washed away by the sea,<br>
Europe is the less,<br>
As well as if a promontory were:<br>
As well as if a manor of thy friend's<br>
Or of thine own were.<br><br>
Any man's death diminishes me,<br>
Because I am involved in mankind.<br>
And therefore never send to know for whom the bell tolls;<br>
It tolls for thee.<br>
<br>
by John Donne <br>
</p>

No man is an island,
Entire of itself;
Every man is a piece of the continent,
A part of the main.

If a clod be washed away by the sea,
Europe is the less,
As well as if a promontory were:
As well as if a manor of thy friend's
Or of thine own were.

Any man's death diminishes me,
Because I am involved in mankind.
And therefore never send to know for whom the bell tolls;
It tolls for thee.

by John Donne

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<p style="text-align:right;">No man is an island,<br>
Entire of itself;<br>
Every man is a piece of the continent,<br>
A part of the main.<br><br>
If a clod be washed away by the sea,<br>
Europe is the less,<br>
As well as if a promontory were:<br>
As well as if a manor of thy friend's<br>
Or of thine own were.<br><br>
Any man's death diminishes me,<br>
Because I am involved in mankind.<br>
And therefore never send to know for whom the bell tolls;<br>
It tolls for thee.<br>
<br>
by John Donne <br>
</p>

No man is an island,
Entire of itself;
Every man is a piece of the continent,
A part of the main.

If a clod be washed away by the sea,
Europe is the less,
As well as if a promontory were:
As well as if a manor of thy friend's
Or of thine own were.

Any man's death diminishes me,
Because I am involved in mankind.
And therefore never send to know for whom the bell tolls;
It tolls for thee.

by John Donne


References