In CSS, text spacing can be adjusted using a few different properties depending on the specific type of spacing you’re aiming to control.
1. Line Height: Controls the vertical spacing between lines of text.
p {
line-height: 1.5; /* or a unit value like 24px */
}
2. Letter Spacing: Adjusts the space between individual characters.
p {
letter-spacing: 3px; /* or other unit values */
}
3. Word Spacing: Modifies the space between words.
p {
word-spacing: 4px; /* or other unit values */
}
4. Text Indent: Indents the first line of text in a block.
p {
text-indent: 20px; /* or other unit values */
}
5. Text Align: Aligns text horizontally within its containing element.
p {
text-align: justify; /* or left, right, center */
}
6. Margin and Padding: Adds space around or inside elements, respectively, which can affect the overall spacing of text within its container.
p {
margin: 20px; /* space outside the element */
padding: 20px; /* space inside the element */
}
CSS text spacing – Interview Questions
Q 1: What is letter-spacing?
Q 2: What is word-spacing?
Q 3: What is line-height?
Q 4: Can spacing be negative?
Q 5: Why is text spacing important?
CSS text spacing – Objective Questions (MCQs)
Q1. Which property controls the space between letters?
Q2. Which property controls the space between words?
Q3. Which property controls the space between lines of text?
Q4. Which property indents the first line of text?
Q5. Which value increases space between letters?