In CSS, text styling plays a crucial role in defining the appearance of content. There are several properties in CSS that allow you to control the font, alignment, spacing, decoration, and other visual aspects of text.
Text Color:
The colorproperty sets the color of the text.
Syntax:
color : color | transparent | initial | inherit;
Example
p {
color: #333; /* Set text color to dark gray */
}
The font-size property controls the size of the text.
Syntax:
font-size : <value>;
Value: Can be specified in various units such as pixels (px), percentages (%), ems (em), rems (rem), viewport units (vw, vh), or keywords like autoand inherit.
Example
p {
font-size: 20px; /* Set font size to 18 pixels */
}
The line-height property controls the space between lines of text (leading). It’s often used to improve readability.
Syntax:
line-height : <value>;
Value: Can be specified in various units such as pixels (px), percentages (%), ems (em), rems (rem), viewport units (vw, vh), or keywords like autoand inherit.
Example
p {
line-height: 1.5; /* Set line height to 1.5 times the font size */
}
The letter-spacing property controls the space between individual characters.
Syntax:
letter-spacing : <value>;
Value: Can be specified in various units such as pixels (px), percentages (%), ems (em), rems (rem), viewport units (vw, vh), or keywords like autoand inherit.
Example
p {
letter-spacing: 2px; /* Adds 2px of space between letters */
}
The word-spacing property controls the space between words.
Syntax:
word-spacing : <value>;
Value: Can be specified in various units such as pixels (px), percentages (%), ems (em), rems (rem), viewport units (vw, vh), or keywords like autoand inherit.
Example
p {
word-spacing: 10px; /* Adds 10px space between words */
}
The text-indent property controls the indentation of the first line of text.
Syntax:
text-indent : <value>;
Value: Can be specified in various units such as pixels (px), percentages (%), ems (em), rems (rem), viewport units (vw, vh), or keywords like autoand inherit.
Example
p {
text-indent: 50px; /* Indent the first line by 50px */
}
The white-space property controls how whitespace is handled, including spaces and line breaks.
Syntax:
white-space : <value>;
Value: Can be specified in various units such as pixels (px), percentages (%), ems (em), rems (rem), viewport units (vw, vh), or keywords like autoand inherit.
Example
p {
white-space: nowrap; /* Prevents text from wrapping to the next line */
}
We use cookies and similar technologies to enhance your browsing experience, serve personalized content and advertisements, and analyze our traffic.
By clicking "Accept All", you consent to our use of cookies and the processing of your personal data for these purposes.
You can manage your preferences or learn more in our
Privacy Policy and
Cookie Policy.