Tillitsdone
down Scroll to discover

CSS Text-Justify Enhance Text Alignment

Discover how the CSS text-justify property enhances text alignment for better readability.

Learn about available options like auto, inter-word, and inter-character.
thumbnail

Introduction

The text-justify CSS property controls how text is justified when text-align: justify; is applied. Justification spreads text evenly across the available space, making it more visually appealing. This property is useful for web design to enhance readability and aesthetics.

Specification

The text-justify property is defined in the CSS Text Module Level 3. You can find the official documentation in the CSS Text Module Level 3 under the section for the text-justify property.

Syntax

Here’s how to use the text-justify property in CSS:

text-justify: none;
text-justify: auto;
text-justify: inter-word;
text-justify: inter-character;
text-justify: distribute; /* Deprecated value */
/* Global values */
text-justify: inherit;
text-justify: initial;
text-justify: revert;
text-justify: revert-layer;
text-justify: unset;

Values

  • none: Turns off text justification.
  • auto: The browser chooses the best justification method.
  • inter-word: Justifies text by adjusting spaces between words.
  • inter-character: Justifies text by adjusting spaces between characters.
  • distribute: Deprecated, behaves like inter-character.

Global values include:

  • inherit: Inherits the text-justify value from the parent element.
  • initial: Sets the property to its default value.
  • revert: Reverts to the user agent’s default stylesheet value.
  • revert-layer: Reverts to the value for the current cascade layer.
  • unset: Resets the property to its initial or inherited value.

Formal Definition

  • Initial Value: auto
  • Applies To: Inline-level and table-cell elements
  • Inherited: Yes
  • Computed Value: As specified
  • Animation Type: Discrete

Examples

Simple Example

Here’s a simple example to demonstrate the different values of text-justify:

<p class="none">
<code>text-justify: none</code> —<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<p class="auto">
<code>text-justify: auto</code> —<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<p class="dist">
<code>text-justify: distribute</code> —<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<p class="word">
<code>text-justify: inter-word</code> —<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<p class="char">
<code>text-justify: inter-character</code> —<br />Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
p {
font-size: 1.5em;
border: 1px solid black;
padding: 10px;
width: 95%;
margin: 10px auto;
text-align: justify;
}
.none {
text-justify: none;
}
.auto {
text-justify: auto;
}
.dist {
text-justify: distribute;
}
.word {
text-justify: inter-word;
}
.char {
text-justify: inter-character;
}

Example with Interactive Buttons

<button onclick="changeJustify('none')">None</button>
<button onclick="changeJustify('auto')">Auto</button>
<button onclick="changeJustify('inter-word')">Inter-Word</button>
<button onclick="changeJustify('inter-character')">Inter-Character</button>
<div id="justify-example" class="justify-example">
Vincent van Gogh is one of the most well-known post-impressionist painters.
</div>
<script>
function changeJustify(value) {
document.getElementById('justify-example').style.textJustify = value;
}
</script>
<style>
.justify-example {
width: 250px;
padding: 15px;
border: 2px solid orangered;
text-align: justify;
text-justify: inter-word;
}
</style>

Browser Compatibility

  • Chrome: Full support.
  • Firefox: Supported from version 55.0.
  • Internet Explorer/Edge: Supported from IE 11.0.
  • Opera: Full support.
  • Safari: Supported from version 10.0.3.

See Also

For more information, check out:

  • [text-align]WebsiteUrl
  • [text-indent]WebsiteUrl
  • [text-overflow]WebsiteUrl
  • [HTML Reference Guide]WebsiteUrl

These resources will help you understand text formatting and alignment in web development, making your web pages more polished and professional.

icons/css-4.svg CSS Blogs
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.