Home 〉 CSS Tutorials 〉 CSS Text Formatting Properties Explained with Examples | Master Text Styles in CSS
CSS Text Formatting Properties Explained with Examples | Master Text Styles in CSS !
Want to change how your text looks in a webpage? CSS text formatting properties like `text-align`, `text-transform`, `line-height`, and `letter-spacing` help you control the appearance of text in your HTML. These properties are key to improving readability and making content more attractive. You'll also learn how to style different blocks of text using classes and IDs. This post will provide you a tutorial on CSS Font Properties
Text is a big part of any webpage. CSS gives us many powerful properties to control how text looks and behaves. In this guide, we'll cover important CSS text formatting properties like:
Let's go through each one step by step with examples.
Controls the horizontal alignment of text.
<!DOCTYPE html>
<html>
<body>
<p style="text-align: center;">This text is centered.</p>
</body>
</html>
output 📌
This text is centered.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values : 'left', 'right', 'center', 'justify'
Controls the spacing between lines.
<!DOCTYPE html>
<html>
<body>
<p style="line-height: 2;">Line height set to 2.</p>
</body>
</html>
output 📌
Line height set to 2.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Accepts : unitless number, px, em, %
Adjusts space between characters.
<!DOCTYPE html>
<html>
<body>
<p style="letter-spacing: 2px;">Wide spaced letters</p>
</body>
</html>
output 📌
Wide spaced letters
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
✅ Use for headings or stylized text.
Sets space between words.
<!DOCTYPE html>
<html>
<body>
<p style="word-spacing: 10px;">Extra space between words.</p>
</body>
</html>
output 📌
Extra space between words.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
✅ Helpful for readability.
Indents the first line of text.
<!DOCTYPE html>
<html>
<body>
<p style="text-indent: 40px;">Indented first line.</p>
</body>
</html>
output 📌
Indented first line.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
✅ Commonly used in articles or paragraphs.
Changes text case.
<!DOCTYPE html>
<html>
<body>
<p style="text-transform: uppercase;">This text is uppercase.</p>
</body>
</html>
output 📌
This text is uppercase.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values : 'uppercase', 'lowercase', 'capitalize', 'none'
Handles overflowed text content in a box.
<!DOCTYPE html>
<html>
<body>
<div style="width: 100px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
This is a very long text that will be truncated.
</div>
</body>
</html>
output 📌
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
✅ Often used with 'ellipsis' for long content.
Values : 'ellipsis', 'clip'
Manages how white space inside elements is handled.
<!DOCTYPE html>
<html>
<body>
<p style="white-space: pre;"> This will keep spacing.</p>
</body>
</html>
output 📌
This will keep spacing.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values : 'normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap'
Controls word breaking rules.
<!DOCTYPE html>
<html>
<body>
<p style="word-break: break-all;">averyveryverylongwordwillbreak</p>
</body>
</html>
output 📌
averyveryverylongwordwillbreak
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
✅ Useful in responsive layouts.
Values : 'break-all', 'keep-all', 'normal'
Wraps words when they're too long.
<!DOCTYPE html>
<html>
<body>
<p style="word-wrap: break-word;">averyveryverylongword</p>
</body>
</html>
output 📌
averyveryverylongword
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Note : 'word-wrap' is now 'overflow-wrap'
Values : 'break-word', 'normal'
Applies justification to text.
<!DOCTYPE html>
<html>
<body>
<p style="text-align: justify; text-justify: inter-word;">
This paragraph is fully justified with equal spacing between words.
</p>
</body>
</html>
output 📌
This paragraph is fully justified with equal spacing between words.
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
✅ Works best when combined with 'text-align: justify'
Values : 'auto', 'distribute', 'distribute-all-lines', 'linter-cluster', 'inter-ideograph', 'inter-word', 'kashida', 'newspaper'
Sets the text direction.
<!DOCTYPE html>
<html>
<body>
<p style="direction: rtl;">This text is from right to left</p>
</body>
</html>
output 📌
This text is from right to left
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
Values : 'ltr' (left to right), 'rtl' (right to left)
Changes the flow direction of text.
<!DOCTYPE html>
<html>
<body>
<p style="writing-mode: vertical-rl;">Vertical text</p>
</body>
</html>
output 📌
Vertical text
You can Try the above code by changing the values in our user-friendly code editor by clicking the "Try It" button and see the output of the same.
✅ Use in vertical writing or creative layouts.
Values : 'horizontal-tb', 'sideways-lr', 'sideways-rl', 'vertical-lr', 'vertical-rl'
Mastering text formatting in CSS helps create cleaner and more readable web pages. These properties allow you to control spacing, alignment, overflow, and even direction of the text — making your layout visually balanced and user-friendly.
'text-align' controls alignment (left, center, right), while 'text-justify' adjusts spacing between words to fill the line width evenly.
Use the 'writing-mode: vertical-rl;' or 'vertical-lr;' property to display text vertically.
Use 'line-height' to control the space between lines of text.
'word-break' breaks long words; 'word-wrap' (now 'overflow-wrap') wraps words when needed to avoid overflow.