bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/CSS/Advanced Styling
CSS•Advanced Styling

CSS Text Effects

CSS has some properties to handle text overflow, word wrapping, line breaking rules and writing modes.

In this chapter you will learn about the following properties:

  • text-overflow - Specifies how to handle overflowed content
  • word-wrap - Allows long words to be able to be broken and wrap onto the next line
  • word-break - Specifies line breaking rules
  • writing-mode - Specifies whether lines of text are laid out horizontally or vertically

CSS text-overflow Property

The CSS text-overflow property specifies how overflowed content that is not displayed should be signaled to the user. It can be clipped or rendered with ellipsis (...).

Both of the following properties are required for text-overflow to take effect:

  • white-space: nowrap;
  • overflow: hidden;

Here, the overflowed content is clipped:

This is some long text that will not fit in the box

Here, the overflowed content is rendered with ellipsis (...):

This is some long text that will not fit in the box

Example

Formatted code
p.test1 {
  width: 200px;
  border: 1px solid #000000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
p.test2 {
  width: 200px;
  border: 1px solid #000000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

Live preview

The CSS code is as follows

The following example shows how you can display the overflowed content when hovering over the element:

Example

Formatted code
p:hover {
  overflow: visible;
}

Live preview

CSS word-wrap Property

The CSS word-wrap property allows long words to be able to be broken and wrap onto the next line.

If a word is too long to fit within an area, it expands outside:

This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.

The word-wrap property allows you to force the text to wrap - even if it means splitting it in the middle of a word:

This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.

Example

Formatted code
p {
  word-wrap: break-word;
}

Live preview

CSS word-break Property

The CSS word-break property specifies how words should break when reaching the end of a line.

This property can take one of the following values:

  • normal - This is default. Uses the default line breaking rules of the language
  • break-all - Allows words to be broken at any character to prevent overflow
  • keep-all - Prevents words from breaking

Here, we use normal :

This paragraph contains some text. This line will-break-at-hyphens.

Here, we use break-all :

This paragraph contains some text. The lines will break at any character.

Example

Formatted code
p.test1 {
  word-break: normal;
}
p.test2 {
  word-break: break-all;
}

Live preview

CSS writing-mode Property

The CSS writing-mode property specifies whether lines of text are laid out horizontally or vertically.

This property can take one of the following values:

  • horizontal-tb - Default. The text flows horizontally from left to right, vertically from top to bottom
  • vertical-rl - The text flows vertically from top to bottom, horizontally from right to left
  • vertical-lr - The text flows vertically from top to bottom, horizontally from left to right

Here is a text with a span element with a vertical-rl writing-mode.

The following example shows some different writing modes:

Example

Formatted code
p.test1 {
  writing-mode: horizontal-tb;
}
span {
  writing-mode: vertical-rl;
}
p.test2 {
  writing-mode: vertical-rl;
}

Live preview

CSS Text Effect Properties

The following table lists the CSS text effect properties:

PropertyDescription
text-justifySpecifies how justified text should be aligned and spaced
text-overflowSpecifies how overflowed content that is not displayed should be signaled to the user
word-breakSpecifies line breaking rules for non-CJK scripts
word-wrapAllows long words to be able to be broken and wrap onto the next line
writing-modeSpecifies whether lines of text are laid out horizontally or vertically

Previous

CSS Box Shadow

Next

CSS Custom Fonts

This chapter

Overview
53

Lessons

154m

Read time

1. CSS Rounded Corners2. Sass Tutorial3. CSS Border Images4. CSS Multiple Backgrounds5. CSS Background Size6. CSS Background Origin7. CSS Background Clip8. CSS Colors9. CSS Color Keywords10. CSS Gradients11. CSS Radial Gradients12. CSS Conic Gradients13. CSS Shadow Effects14. CSS Box Shadow15. CSS Text Effects16. CSS Custom Fonts17. CSS 2D Transforms18. CSS 2D Transform Scale19. CSS 2D Transform Skew / Matrix20. CSS 3D Transforms21. CSS Transitions22. CSS Transition Timing23. CSS Animations24. CSS Animation Timing25. CSS Animation Properties26. CSS Tooltip27. CSS Tooltip Arrows28. CSS Styling Images29. CSS Image Effects30. CSS Image Hover Overlays31. CSS Responsive Modal Images32. CSS Centering Images33. CSS Image Filter Effects34. CSS Image Shapes35. CSS object-fit Property36. CSS object-position Property37. CSS Masking38. CSS Gradient Mask Layers39. CSS SVG Mask Layers40. CSS Styling Buttons41. CSS Button Hover Effects42. CSS Button Groups43. CSS Pagination Styles44. CSS Multiple Columns45. CSS Column Rules46. CSS User Interface47. CSS Variables - var() Function48. CSS Overriding Variables49. CSS Variables and JavaScript50. CSS Variables in Media Queries51. CSS @property Rule52. CSS Box Sizing53. CSS Media Queries

On this page

CSS text-overflow PropertyCSS word-wrap PropertyCSS word-break PropertyCSS writing-mode PropertyCSS Text Effect Properties