Currently Empty: ₹0.00
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.
06
text-align-last
Control the alignment of the last line
The text-align-last property specifies how the last
line of a block-level element is aligned.
text-align-last.css
p {
text-align: justify;
text-align-last: center;
}CSS text alignment helps create clean and readable paragraphs. The last line can be aligned separately when required.
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;
}
13
Responsive Text Alignment
Change alignment on smaller screensCSS media queries can change text alignment according to screen size. For example, a heading can be centered on mobile devices.
responsive-alignment.css
.heading {
text-align: left;
}
@media (max-width: 600px) {
.heading {
text-align: center;
}
}Responsive Heading
Resize the browser window to see the alignment behavior.
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 sectionABOUT 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.
18
CSS Text Alignment Live Runner
Experiment with alignment propertiesLIVE PREVIEW
19
Quick Reference
Important properties at a glancetext-align
Controls horizontal text alignment.text-align-last
Controls the last line alignment.direction
Controls text direction.unicode-bidi
Controls bidirectional text behavior.


