CSS Text Effects
CSS Text Overflow, Word Wrap, Line Breaking Rules, and Writing Modes
In this part, you'll find details about these features:
text-overflow
word-wrap
word-break
writing-mode
CSS Text Overflow
The CSS text-overflow
property tells us how to show users when content overflows and is not visible.
It can be clipped:
This text is too long to fit inside the box.
You may also see it as three dots (...) when it's shown on the screen..
This text is too long to fit inside the container.
Here is the CSS code:
Here's an easy method to display additional content when you move your mouse pointer over something in HTML:
CSS Word Wrapping
The word-wrap
CSS property helps long words break and go to the next line when needed.
If a word is too long to fit within a designated area, it extends outside the defined boundaries.
This text has a super-duper long word: thisisaveryveryveryveryveryverylongword. The really long word will break and go to the next line.
The word-wrap property helps text move to the next line when needed, even if it has to break a word in two.
thisisaveryveryveryveryveryverylongword. The lengthy word will split and continue on the next line.
Here is the CSS code:
CSS Word Breaking
The CSS property called word-break
helps determine how to split lines of text.
This paragraph has some words. This line will split at hyphens.
This paragraph has some words. It will split at any letter or symbol.
Here is the CSS code:
CSS Writing Mode
The writing-mode
CSS property determines whether text lines should be horizontal (side by side) or vertical (up and down).
Here is some text that contains a part with a special style called 'wmtest2,' and it's written in a way that goes from top to bottom, like in vertical writing.
The example below demonstrates various ways of writing text:
<!DOCTYPE html>
<html>
<head>
<style>
p.test1 {
white-space: nowrap;
width: 200px;
border: 1px solid #000000;
overflow: hidden;
text-overflow: clip;
}
p.test2 {
white-space: nowrap;
width: 200px;
border: 1px solid #000000;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<h1>The text-overflow Property</h1>
<p>The following two paragraphs contains a long text that will not fit in the box.</p>
<h2>text-overflow: clip:</h2>
<p class="test1">This is some long text that will not fit in the box</p>
<h2>text-overflow: ellipsis:</h2>
<p class="test2">This is some long text that will not fit in the box</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div.test {
white-space: nowrap;
width: 200px;
overflow: hidden;
border: 1px solid #000000;
}
div.test:hover {
overflow: visible;
}
</style>
</head>
<body>
<p>Hover over the two divs below, to see the entire text.</p>
<div class="test" style="text-overflow:ellipsis;">This is some long text that will not fit in the box</div>
<br>
<div class="test" style="text-overflow:clip;">This is some long text that will not fit in the box</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
p.test {
width: 11em;
border: 1px solid #000000;
word-wrap: break-word;
}
</style>
</head>
<body>
<h1>The word-wrap Property</h1>
<p class="test">This paragraph contains a very long word: thisisaveryveryveryveryveryverylongword. The long word will break and wrap to the next line.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
p.test1 {
width: 140px;
border: 1px solid #000000;
word-break: keep-all;
}
p.test2 {
width: 140px;
border: 1px solid #000000;
word-break: break-all;
}
</style>
</head>
<body>
<h1>The word-break Property</h1>
<p class="test1">This paragraph contains some text. This line will-break-at-hyphens.</p>
<p class="test2">This paragraph contains some text. The lines will break at any character.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
p.test1 {
writing-mode: horizontal-tb;
}
span.test2 {
writing-mode: vertical-rl;
}
p.test2 {
writing-mode: vertical-rl;
}
</style>
</head>
<body>
<h1>The writing-mode Property</h1>
<p class="test1">Some text with default writing-mode.</p>
<p>Some text with a span element with a <span class="test2">vertical-rl</span> writing-mode. </p>
<p class="test2">Some text with writing-mode: vertical-rl.</p>
</body>
</html>