How to make an indent between words in CSS

Learn how to add space between words in CSS with a simple example. Create consistent spacing between words and make text easier to read.

Indenting Between Words in CSS

In CSS, indenting between words can be achieved using the text-indent property. It specifies the indentation of the first line of a text block. The text-indent property can take values in length, percentage and other units. Here is an example of how to use it:


p {
  text-indent: 50px;
}

The above code snippet sets the indentation of the first line of a <p> element to 50px. You can adjust this value depending on the desired indentation. You can also set the indentation to a percentage, for example:


p {
  text-indent: 10%;
}

The above code snippet sets the indentation of the first line of a <p> element to 10% of the width of the containing block. You can also set the indentation in other units such as em, rem, vw, vh, etc.

You can also set the indentation of the first line of a <p> element using the text-indent property in combination with the direction property. For example:


p {
  direction: rtl;
  text-indent: 10%;
}

The above code snippet sets the indentation of the first line of a <p> element to 10% of the width of the containing block and sets the text direction to right-to-left. You can also set the indentation of the first line of a <p> element using the text-indent property in combination with the text-align property. For example:


p {
  text-align: center;
  text-indent: 10%;
}

The above code snippet sets the indentation of the first line of a <p> element to 10% of the width of the containing block and sets the text alignment to center. You can also set the indentation of the first line of a <p> element using the text-indent property in combination with other CSS properties. For example:


p {
  text-align: center;
  text-indent: 10%;
  padding: 10px;
  margin: 10px;
}

The above code snippet sets the indentation of the first line of a <p> element to 10% of the width of the containing block, sets the text alignment to center, and adds 10px of padding and margin to the element.

In summary, the text-indent property can be used to set the indentation of the first line of a text block. It can take values in length, percentage, and other units. You can also set the indentation of the first line of a <p> element using the text-indent property in combination with the direction and text-align properties, as well as other CSS properties.

Answers (0)