text-align

lets take a look at the text-align property

text-align is the CSS property that sets the horizontal alignment of text inside a parent container element.

taught by Tina May

text-align can be set to the left, right or center

You can set your text content to align to the left, right or center:

text-align:

Tuition is valuable, but you know what's invaluable? Intuition.

I know what to do. But in a much more real sense, I had no idea what to do.

You miss 100% of the shots you never take.

text-align can be set to the justify

You can set your text content alignment to justify - spreading each word evenly to fill the entire width of the container:

text-align:

Tuition is valuable, but you know what's invaluable? Intuition.

I know what to do. But in a much more real sense, I had no idea what to do.

You miss 100% of the shots you never take.

text-align can be inherited

You can apply text-align to a parent container and all of its child elements will automatically inherit its value. That way you don’t have to apply the property to each child individually.

text-align:

Tip: If you want to center anchor links and other inline text elements, apply the text-align to the parent container instead.

Tuition is valuable, but you know what's invaluable? Intuition.

I know what to do. But in a much more real sense, I had no idea what to do.

You miss 100% of the shots you never take.

text-align can be applied to specific element

You can apply text-align to a specific element by using a class or an ID selector to target that element.

text-align:

Tuition is valuable, but you know what's invaluable? Intuition.

I know what to do. But in a much more real sense, I had no idea what to do.

You miss 100% of the shots you never take.

explore all typography properties

Select any property below and we’ll show you step-by-step how to use the property, with video demo, tips and practical examples you can code for yourself.

color

font-family

font-size

font-style

font-weight

font

letter-spacing

line-height

list-style

text-align

text-decoration

text-indent

text-overflow

text-shadow

text-transform

vertical-align

word-spacing

Try it for yourself

HTML

<div>
  <h2>Oh hey guys!</h2>
  <p>What's brewing, good looking?</p>
  <div class="link-section"><a href="#"> This is an inactive link </a>
  </div>
</div>

Oh hey guys!

What's brewing, good looking?

CSS

/* Change the text alignment of the heading*/

h2 { text-align: center; }

/* Change the text alignment of the paragraph*/

p { text-align: left; }

/* You can try setting the text alignment of the link directly, but this won't move it on the page*/

a { text-align: left; }

/* Try setting the text alignment of the parent container of the link (this will change the link as well)*/

.link-section { text-align: left; }

reults

Try changing the text alignment of our heading, paragraph and anchor link below either to the left, right, center or make it as justify.

Try these:

Copyright 2023