text-justify Property in CSS


The text-justify property in CSS is used to set the justification method of text when the text-align property is set to the justify value. Let us see the syntax −

text-justify: value;

The value here can be any of the following −

  • auto− Sets automatically and the web browser determines

  • inter-word− To increase or decrease the space between words

  • inter-character− To increase or decrease the space between characters

  • none− The justification method is disabled

The syntax can also be seen like this −

text-justify: auto|inter-word|inter-character|none|initial|inherit;

Inter-word justification of text

In this example, we have taken the text-justify property with the value inter-word to increase or decrease the space between words −

text-justify: inter-word;

Example

Let us now see an example to implement the text-justify property in CSS with the value inter-word −

<!DOCTYPE html>
<html>
<head>
   <style>
      div {
         text-align: justify;
         text-justify: inter-word;
         color: white;
         background-color: gray;
      }
   </style>
</head>
<body>
   <h2>Demo Heading</h2>
   <div>This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. This is demo text. </div>
</body>
</html>

Inter-character justification of text

In this example, we have taken the text-justify property with the value inter-character to increase or decrease the space between characters −

text-justify: inter-character;

Example

Let us now see an example to implement the text-justify property in CSS with the value inter-character −

<!DOCTYPE html>
<html>
<head>
   <style>
      article {
         margin: 3%;
         background-color: peachpuff;
         text-align: justify;
      }
      p:first-of-type{	
         text-justify: inter-character;
         background-color: moccasin;
      }
   </style>
</head>
<body>
   <article>
      <p>Nullam in fringilla ex, at sagittis erat. Praesent imperdiet augue at ante tempor, eu condimentum tellus consectetur. Mauris rutrum, lectus quis porta bibendum, arcu neque dictum orci, sed volutpat ipsum risus in ex. Suspendisse potenti. Nam rhoncus ultricies nisi pulvinar rutrum. Mauris ullamcorper interdum urna a vulputate. Quisque dolor tortor, vehicula in odio eu, fringilla rutrum est. Nunc viverra congue aliquam. Ut volutpat magna ipsum, in interdum velit mollis ac. </p>
      <p>Nullam in fringilla ex, at sagittis erat. Praesent imperdiet augue at ante tempor, eu condimentum tellus consectetur. Mauris rutrum, lectus quis porta bibendum, arcu neque dictum orci, sed volutpat ipsum risus in ex. Suspendisse potenti. Nam rhoncus ultricies nisi pulvinar rutrum. Mauris ullamcorper interdum urna a vulputate. Quisque dolor tortor, vehicula in odio eu, fringilla rutrum est. Nunc viverra congue aliquam. Ut volutpat magna ipsum, in interdum velit mollis ac.</p>
   </article>
</body>
</html>

Updated on: 28-Dec-2023

129 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements