
- CSS Tutorial
- CSS - Home
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Measurement Units
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursors
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS Advanced
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Media Types
- CSS - Paged Media
- CSS - Aural Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS3 Tutorial
- CSS3 - Tutorial
- CSS3 - Rounded Corner
- CSS3 - Border Images
- CSS3 - Multi Background
- CSS3 - Color
- CSS3 - Gradients
- CSS3 - Shadow
- CSS3 - Text
- CSS3 - Web font
- CSS3 - 2d transform
- CSS3 - 3d transform
- CSS3 - Animation
- CSS3 - Multi columns
- CSS3 - User Interface
- CSS3 - Box Sizing
- CSS Responsive
- CSS - Responsive Web Design
- CSS References
- CSS - Questions and Answers
- CSS - Quick Guide
- CSS - References
- CSS - Color References
- CSS - Web browser References
- CSS - Web safe fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
Set Text Alignment Working with CSS
Using CSS text-align property we can horizontally set the text of an element. We can set it to left, right, justify or center.
Syntax
The syntax of CSS text-align property is as follows −
Selector { text-align: /*value*/ }
Example
The following exmples illustrate CSS text-align property −
<!DOCTYPE html> <html> <head> <style> div { margin: auto; padding: 8px; max-width: 200px; border: thin solid; } p { text-align: right; } div:nth-child(3) { text-align: center; } div:last-child { text-align: justify; } </style> </head> <body> <h2>Student Examination Details</h2> <div> <div>Student John</div> <div> Student Tom <p>Did not appeared for the exams.</p> </div> <div>Student Brad</div> <div>Did not appeared for only the last exam.</div> </div> </body> </html>
Output
This gives the following output −
Example
<!DOCTYPE html> <html> <head> <style> td { padding: 10px; box-shadow: inset 0 0 21px yellow; } td:first-of-type { text-align: right; } </style> </head> <body> <h2>Demo Heading</h2> <table> <tr> <td>This is it!</td> </tr> <tr> <td>Well, this is a demo text!</td> </tr> </table> </body> </html>
Output
This gives the following output −
- Related Articles
- Set Text Alignment using CSS
- Text Indentation Working with CSS
- Text Transformation Working with CSS
- Setting Text Alignment using CSS
- Setting Text Color Working with CSS
- How to set the horizontal alignment of text with JavaScript?
- How to set Text alignment in HTML?
- How to set alignment to text in text flow layout?
- How to set the text alignment of Text using FabricJS?
- Set the text shadow around a text with CSS
- Java Program to set alignment for text in JLabel
- How to set the text alignment in IText using FabricJS?
- Set the direction of a text with CSS
- Working with Inline CSS
- Working with CSS Units

Advertisements