×

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 Animation

CSS Animation: The animation property of CSS is applied to make animation over any webpage. It is used as the animation replacement made by JavaScript and Flash. Rules of CSS3 @keyframes The...

3 minutes read.

CSS Images

Images in CSS: Images are a critical part of a web application. It includes various types of images in the web application that cannot be recommended. However, it is essential...

4 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

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 Align

CSS Center Align Elements CSS center align is used to create align by using block element. You should specify margin: auto;properties. The element will take up the specified width and the remaining space....

2 minutes read.

CSS Page-break-after Attribute

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

5 minutes read.

CSS 3D Transform

Introduction To understand 3D transformation property of transform you need to first understand the difference between 2D and 3D transform. 2D transform is a CSS effect which transforms the elements according to...

6 minutes read.

CSS Gradient

CSS Gradient: The CSS gradient property is applied to show the smooth transition inside two specified colors or more than two specified colors. Need of CSS Gradient The following are a few...

4 minutes read.

How to center a button in CSS

How to center a button in CSS? In the tutorial, we will learn how to center a button in CSS. CSS (Cascading Style Sheets) gives an HTML web page the greatest possible...

4 minutes read.

CSS Navigation bar

CSS Navigation bar: A navigation system or navigation bar comes upon GUI that can help many visitors to access the information. A Navigation bar is a UI component on the...

11 minutes read.

CSS Hover

CSS Hover: CSS :hover is used to select the various elements whenever we point the mouse on these elements. We can also use this selector on all the HTML elements,...

3 minutes read.

CSS Important

CSS Important: CSS !important property is used to provide more importance, as compared to other CSS properties. The meaning of this property is “This is important.” This property enables CSS...

2 minutes read.

CSS Dropdowns

Dropdowns are one of the maximum crucial parts of an interactive internet site. CSS is a kind used to design the drop-down menus. A drop-down essentially is a group of...

5 minutes read.

CSS Variables

CSS Variables These variables of CSS are applied to add the custom property values to our various web-pages. The custom properties are often called as CSS variables or cascading variables. Various...

4 minutes read.

CSS Padding

CSS Padding: The padding property in CSS is addressed to describe the space among the element border and the element content.This property is quite different from the margin property of...

2 minutes read.

CSS Math Functions

The CSS math functions permit numerical articulations. These CSS math functions can particularly be utilized in maybe unforeseen ways, for example, inside angles and shading the functions and in the...

3 minutes read.

CSS Comments

CSS Comments: Generally, comments in CSS are used to describe our code. Further, it will provide support to many users who are concerned with the code. Somewhat, these are ignored...

2 minutes read.

CSS Text-stroke

Text-stroke Text-stroke CSS property inserts the stroke to any text and gives a decoration option to them also. It describes the stroke’s width and color for various text characters. It is...

2 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

CSS Zoom

CSS Zoom: Zoom property in CSS extents the content. This property controls the content’s level of magnification. Rather than the use of this CSS property, we may also apply the...

3 minutes read.