×

CSS Text Effects

Text Effects in CSS

We can use distinct text effects used inside the HTML document. Few attributes can be applied to insert the text effects.

We can also style various web documents that will affect distinct text with the help of CSS. The text effect properties support us in designing the text clear and attractive. We are listing some essential CSS text effect properties below:

  • word-wrap
  • word-break
  • text-overflow
  • writing-mode

Let’s explain the above properties one by one, along with an example.

word-wrap

It is applied for breaking any lengthy word and, after that, wrap towards any next line. The word-wrap attribute can be used to avoid the overflow if any unbreakable word is too lengthy to fit within any containing box.

Syntax:

word-wrap: normal| break-word| inherit ;  

Property Values

normal: It is applied to break the words at permitted breakpoints only.

break-word: This property of CSS is applied to break distinct unbreakable words.

initial: It sets this attribute to the default value.

inherit: It is used to acquire this attribute by its parent component.

Example:

<!DOCTYPE html>
<html>
<head>
<title> word-wrap property </title>
<style>
.exp
{
 width: 200px;
 border: 2px solid red;
 padding: 10px;
 font-size: 20px;
 background-color: lightgreen;
}
.exp1
{
 width: 11em;
 border: 2px solid red;
 padding: 10px;
 word-wrap: break-word;
 font-size: 25px;
 background-color: lightgreen;
}
</style>
</head>
<center>
<body>
<h1> Without, word-wrap </h1>
<p class= "exp"> We are defining a very lengthy word:
heloooooooooooooooooooooooworldddddddddddddddddddd.
</p>
<h1> With, word-wrap: break-word; </h1>
<p class= "exp1"> We are defining a very lengthy word:
heloooooooooooooooooooooooworldddddddddddddddddddd. This word is breaking and wrapping onto the next line.
</p>
</body>
</center>
</html>

Output:

CSS Text Effects

word-break

This CSS property describes how words must break at any line’s end. The rules of line break can be defined using this property.

Syntax:

word-break: normal |keep-all |  break-all | inherit ;  

Note: The normal value is its default value. Thus, it will automatically apply when we do not define the value.

Property Values

keep-all: This value is used to break any word to its default style.

break-all: This property value adds any word break among many characters to avoid any kind of word overflow.

Example:

<!DOCTYPE html>
<html>
<head>
<title> word-break: break-all; </title>
<style>
.exp
{
 width: 150px;
 border: 2px solid red;
 word-break: break-all;
 text-align: left;
 font-size: 25px;
 color: green;
}
.exp1
{
 width: 156px;
 border: 2px solid red;
 word-break: keep-all;
 text-align: left;
 font-size: 25px;
 color: green;
}
</style>
</head>
<center>
<body>
<h2> word-break: break-all; </h2>
<p class= "exp">
 Welcome to this Page.
</p>
<h2> word-break: keep-all; </h2>
<p class= "exp1">
 Welcome to this Page.
</p>
</body>
</center>
</html>

Output:

CSS Text Effects

text-overflow

It describes the illustration of overflowed content, which is invisible to any user. This CSS property indicates the user regarding the text that is invisible. It supports us to determine whether the content must be cut or display few dots (ellipsis).

Note: It does not apply by its own. We need to apply overflow: hidden; and white-space: nowrap; along with this attribute.

Syntax:

text-overflow: clip | ellipsis;  

Property Values

clip: This value is a default value. It is sued to clip the overflowed content.

ellipsis: It shows three dots (…) or ellipsis to display the clipped content. This value is shown inside the area, reducing the txt amount.

Example:

<!DOCTYPE html>
<html>
<head>
<title> text-overflow property </title>
<style>
.exp
{
 white-space: nowrap;   
 height: 30px; 
 width: 250px;                
 overflow: hidden;   
 border: 2px solid red;  
 font-size: 25px;  
 text-overflow: clip;  
}
.exp1
{
 white-space: nowrap;   
 height: 30px; 
 width: 250px;                
 overflow: hidden;   
 border: 2px solid red;  
 font-size: 25px;  
 text-overflow: ellipsis; 
}
h2
{
 color: green;
}
div:hover
{
 overflow: visible;
}
p
{
 font-size: 25px; 
 font-weight: bold; 
 color: blue; 
}
</style>
</head>
<center>
<body>
<p> Hover on the bordered content to examine the effect. </p>
<h2> text-overflow: clip; </h2>
<div class= "exp"> Hello all! Welcome to this Page </div>
<h2> text-overflow: ellipsis; </h2>
<div class= "exp1"> Hello all! Welcome to this Page </div>
</body>
</center>
</html>

Output:

CSS Text Effects

writing-mode

This property describes that the content will be specified either in vertical or horizontal direction. If the specified direction is horizontal, then it will be from right to left (vertical-rl) or from left to right (vertical-lr).

Syntax:

writing-mode: horizontal-tb | vertical-lr | vertical-rl | inherit ; 

Property Values

horizontal-tb: This property value is used as default value for this property, where the content will be in the horizontal direction. It will be consider from top to bottom and left to right.

vertical-rl: This value is used to show the content in vertical direction. The content will be consider from top to bottom and right to left.

vertical-lr: This value is same as the vertical-rl, although the content will be consider from the left side to the right side.

Example:

<!DOCTYPE html>
<html>
<head>
<title> writing-mode property </title>
<style>
h2
{
 border: 2px solid navy;
 width: 300px;
 height: 100px;
}
#tb
{
writing-mode: horizontal-tb;
}
#lr
{
writing-mode: vertical-lr; 
} 
#rl
{ 
writing-mode: vertical-rl; 
} 
</style>
</head>
<center>
<body>
<h1> Illustration of writing-mode property </h1>
<h2 id= "tb"> writing-mode: horizontal-tb; </h2>
<h2 id= "lr" style= "height: 300px;"> writing-mode: vertical-lr; </h2><br>
<h2 id= "rl" style= "height: 300px;"> writing-mode: vertical-rl; </h2>
</body>
</center>
</html>

Output:

CSS Text Effects

Related Topics

CSS Float

CSS Float: The float property of CSS is the positioning property. This property is applied to elements to push them either to left or right. It permits for wrapping facility...

4 minutes read.

Css Box Model

Introduction The Box Model property of CSS is used for design and layout of an html page. In CSS, all the elements has a rectangular box around it, you have to...

5 minutes read.

CSS Text-Transform Property

Text-Transform in CSS The text-transform property permits us to alter the text case. It controls the capitalization of the text. This property is employed to design the text appearance in every...

3 minutes read.

CSS Display

CSS Display: The CSS Display property is one of an essential property among all other properties of CSS. The display property specifies how the HTML elements should be displayed on...

4 minutes read.

CSS calc()

CSS calc(): The CSS calc() function is a CSS function of inbuilt type, which permits us to implement calculations. It is used for calculating the angle, integer frequency, number, time,...

3 minutes read.

CSS Font

CSS Font: CSS has font property, which makes the text more attractive. We can alter the entire look by changing font color, font size, font style, and much more. In...

5 minutes read.

CSS Button Style

CSS button style: Using CSS properties, we can easily modify the default BUTTON and enhance its appearances using simple graphic commands. TYPES OF BUTTON STYLE: - Program to change button using CSS ...

35 minutes read.

CSS Content Property

Content Property The content attribute produces dynamic content. It can be applied with any pseudo-element ::after and ::before. These CSS properties are entirely supported inside every browser and applied to include...

5 minutes read.

CSS Page-break-before Attribute

Page-break-before Attribute As its name implies, the page-break-before property is applied to include page break before any element, at the time of printing any document. It adds the page break before...

5 minutes read.

CSS Text-decoration

CSS Text-decoration: It is an essential property of CSS that is used to decorate the content of the text. It can add-on the lines above, under, and over the text....

3 minutes read.

How to create blinking text using CSS

The blinking effect is used in HTML and CSS to take the attraction towards a particular word or section. If you need such a blinking effect, we need to take...

2 minutes read.

CSS Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

CSS Border

CSS Border: The border property of CSS allows us to define the style, color, width, and radius of the element’s border. It is applied to various elements to set-up the...

4 minutes read.

CSS Position

CSS Position: The position property in CSS is applied to set the position of the elements. It can be used to position the backside of an element. It is also...

3 minutes read.

CSS Introduction

CSS stands for Cascading Style Sheet. It is a design language which is used to design the web pages. It was developed by Håkon Wium Lie on October 10, 1994. It provides...

1 minute read.

CSS Overlay

CSS Overlay: It measures to cover-up something’s surface along with a coating. CSS overlay sets anything over the top area of other things. It creates a web-page more attractive. The...

8 minutes read.

CSS Letter-spacing

CSS Letter-spacing: Letter-spacing attribute is applied to manage the space among all letters within the block or element of the text. This property sets the behavior of the spacing between...

2 minutes read.

CSS Transition

CSS Transition The transitions in CSS are influenced, included to modify the component from one design to another, without the use of the JavaScript or Flash. We should describe two of the...

2 minutes read.

CSS Order

CSS Order CSS order property in CSS describes the flex item’s order inside the flex or any grid container. It is applied to order any flex item. Note: If any component is...

3 minutes read.