DEV Community

Prakriti Anand
Prakriti Anand

Posted on

4 CSS tricks, You should try!

1. Balancing Text

With CSS's new text-wrap feature, centering headers is now simpler across all devices.

text-wrap property demo image

h1 {
  text-wrap: balance;
}
Enter fullscreen mode Exit fullscreen mode

text-wrap is a new property in CSS, so I recommend checking browser compatibility before using it in production.

2. Text Indent

The CSS text-indent property indents the first line of a paragraph to improve readability.

text indent property demo

p {
  text-indent: 0.25rem;
}
Enter fullscreen mode Exit fullscreen mode

3. Truncating Text

Sometimes, to prevent large sentences from making a UI look bad, we can simply truncate the text using CSS.

Truncate text demo image

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
Enter fullscreen mode Exit fullscreen mode

4. Fixed number of lines (Line Clamp)

Occasionally, it’s necessary to limit the number of lines displayed. Use this simple technique to achieve it.

line clamp demo image

p {
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3; /* Number of Lines */
}
Enter fullscreen mode Exit fullscreen mode

It's over!

Thanks for reading πŸ‘‹

Top comments (0)