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 color property sets the color of the text.
Syntax: color : color | transparent | initial | inherit;
Example
p {
color : #333 ; /* Set text color to dark gray */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Text Alignment: The text-align property aligns the text within its containing element.
Syntax: text-align : left | right | center | justify;
Example
p {
text-align: center; /* Align text to the center */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Try It:
Left
Right
Center
Justify
This is the first paragraph.
Currently Active Property:
Font Family: The font-family property specifies the typeface of the text. You can provide a list of fallback fonts.
Example
p {
font-family: 'Arial' , sans-serif; /* Set text to Arial or a sans-serif font */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Font Size: 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 auto and inherit .
Example
p {
font-size: 20 px; /* Set font size to 18 pixels */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Font Weight: The font-weight property sets the thickness (or boldness) of the text.
Syntax: font-weight : normal | bold | lighter | bolder | 100-900;
Example
p {
font-weight: bold; /* Bold text */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Try It:
Normal
Lighter
Bold
Bolder
600
Currently Active Property:
Font Style: The font-style property sets the thickness (or boldness) of the text.
Syntax: font-style : normal | italic | oblique;
Example
p {
font-style: italic; /* Italicize the text */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Try It:
Currently Active Property:
Text Decoration: The text-decoration property is used to set decorations like underlines, overlines, or strikethroughs.
Syntax: text-decoration : none | underline | line-through | overline;
Example
a {
text-decoration: underline; /* Underline text */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Try It:
None
Underline
Overline
Line-through
Currently Active Property:
Text Transform: The text-transform property controls the capitalization of the text.
Syntax: text-transform : none | uppercase | lowercase | capitalize;
Example
p {
text-transform: uppercase; /* Convert text to uppercase */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Try It:
None
Uppercase
Lowercase
Capitalize
Currently Active Property:
Line Height: 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 auto and inherit .
Example
p {
line-height: 1.5 ; /* Set line height to 1.5 times the font size */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Letter Spacing: 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 auto and inherit .
Example
p {
letter-spacing: 2 px; /* Adds 2px of space between letters */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Word Spacing: 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 auto and inherit .
Example
p {
word-spacing: 10 px; /* Adds 10px space between words */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Text Indentation: 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 auto and inherit .
Example
p {
text-indent: 50 px; /* Indent the first line by 50px */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
White Space: 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 auto and inherit .
Example
p {
white-space: nowrap; /* Prevents text from wrapping to the next line */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Text Shadow: The text-shadow property adds shadows to the text, with options for the shadow's position, blur radius, and color.
Syntax: text-shadow : [horizontal offset] [vertical offset] [blur radius] [color];
Example
p {
text-shadow: 2 px 2 px 5 px rgba(0 , 0 , 0 , 0.3 ); /* Adds a shadow */
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself
Example of Multiple Text Properties
p {
font-family: 'Verdana' , sans-serif;
font-size: 24 px;
font-weight: bold;
color : #007 BFF;
text-align: center;
text-transform: uppercase;
letter-spacing: 1 px;
text-shadow: 2 px 2 px 3 px rgba(0 , 0 , 0 , 0.2 );
}
show = true, 3000)" class=" absolute top-[10px] right-[10px] inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 hover:bg-accent hover:text-accent-foreground transition-smooth h-9 rounded-md px-3 cursor-pointer">
Try it yourself