Breadcrumb Abstract Shape
Breadcrumb Abstract Shape
Breadcrumb Abstract Shape

CSS Text Alignment

CSS Text Alignment

CSS CODES & EXAMPLES

CSS Text Alignment

Learn how to align text horizontally, control the last line, handle text direction and create professional responsive layouts.

01

What is Text Alignment?

Position text inside its container

CSS text alignment controls how inline content such as text is positioned horizontally inside an element. The main property used for this purpose is text-align.

CSS Property: text-align
02

text-align: left

Align text to the left

The left value places text against the left side of its containing block.

text-align-left.css
p {
  text-align: left;
}

This text is aligned to the left.

03

text-align: center

Center text horizontally

The center value places text in the horizontal center of its containing block.

text-align-center.css
h2 {
  text-align: center;
}

CSS Text Alignment

04

text-align: right

Align text to the right

The right value places text against the right side of its containing block.

text-align-right.css
p {
  text-align: right;
}

This text is aligned to the right.

05

text-align: justify

Create even text edges

The justify value stretches lines so that text occupies the available width, creating an even left and right edge.

text-align-justify.css
p {
  text-align: justify;
}

CSS is used to style webpages and control the visual presentation of text, layouts, colors, spacing, typography and responsive interfaces. Text alignment is an important part of creating readable and professional content.

07

Text Direction

Left-to-right and right-to-left text

The direction property specifies the direction of text. It is commonly used with languages written from right to left.

direction.css
.ltr {
  direction: ltr;
}

.rtl {
  direction: rtl;
}
LTR

Left to Right Text

RTL

Right to Left Text

08

unicode-bidi

Control bidirectional text behavior

The unicode-bidi property works with direction to control how bidirectional text is handled.

unicode-bidi.css
.example {
  direction: rtl;
  unicode-bidi: embed;
}
Computer Education
09

Horizontal Alignment Examples

Compare all major alignment values
LEFT

Learning makes progress possible.

CENTER

Learning makes progress possible.

RIGHT

Learning makes progress possible.

JUSTIFY

Learning makes progress possible through practice and consistent effort.

10

Text Alignment in Cards

Professional course-card layout
FEATURED COURSE ONLINE

Diploma in Computer Application

Build practical computer skills through structured lessons, hands-on exercises and career-focused learning.

DURATION 6 Months
View Course →
course-card-alignment.css
.course-card {
  text-align: left;
}

.course-card h3 {
  text-align: left;
}

.course-card-bottom a {
  text-align: center;
}
11

Text Alignment in Buttons

Center text inside buttons
button-alignment.css
.button {
  display: inline-block;
  text-align: center;
  padding: 12px 22px;
}
12

Text Alignment in Navigation

Create balanced navigation links
navigation.css
.navigation a {
  display: inline-block;
  text-align: center;
  text-decoration: none;
}
14

Common Alignment Values

Quick visual reference
Value Purpose
left Align text to the left.
center Center text horizontally.
right Align text to the right.
justify Stretch text across the available width.
start Align according to the writing direction.
end Align opposite to the start direction.
15

Practical Website Example

Institute introduction section
ABOUT OUR INSTITUTE

Learn. Practice. Grow.

Shree Narayan Computers & Education Center provides practical computer education, digital skills and career-oriented learning opportunities for students and learners.

Learn More →
institute-section.css
.institute-demo {
  text-align: center;
}

.institute-demo h2 {
  text-align: center;
}

.institute-demo p {
  text-align: center;
  line-height: 1.8;
}

.institute-demo a {
  text-align: center;
}
16

Best Practices

Use text alignment correctly
✓ Use center alignment

Useful for headings, hero sections, buttons and short content.

✓ Use left alignment

Usually the easiest alignment for long-form English content.

✓ Use justify carefully

Justified text can create uneven word spacing on narrow screens.

✓ Test on mobile

Always check text alignment at different viewport widths.

17

Practice Task

Test your CSS Text Alignment skills

🎯 Your Challenge

Create a professional course section using CSS text alignment.

  • Align the main heading to the center.
  • Align the course description to the left.
  • Use justified text for a long paragraph.
  • Center the enrollment button.
  • Use a media query for mobile alignment.
  • Experiment with text-align-last.
19

Quick Reference

Important properties at a glance
text-align Controls horizontal text alignment.
text-align-last Controls the last line alignment.
direction Controls text direction.
unicode-bidi Controls bidirectional text behavior.
`;document.getElementById( "sncecAlignmentPreview" ).srcdoc=html;}document.addEventListener( "DOMContentLoaded", function(){sncecAlignmentRun();} );

CSS Flex Flow

  • 19/08/2026

CSS Fonts

  • 19/08/2026

HTML CSS

  • 17/08/2026

Leave a Reply

Your email address will not be published. Required fields are marked *