CSS Text
CSS provides several properties for styling text on web pages. Here are some common CSS text properties:
color
: This property is used to specify the color of text on a web page. You can use a color name, hexadecimal value, RGB or HSL value. For example:
h1 { color: #333; }
In this example, we’re setting the color ofh1
elements to a dark gray.
text-align
: This property is used to specify the horizontal alignment of text. You can use values such asleft
,center
, andright
. For example:
In this example, we’re centering the text ofp
elements.
text-decoration
: This property is used to add or remove decorations such as underline, overline, and line-through. For example:
a { text-decoration: none; } a:hover { text-decoration: underline; }
In this example, we’re removing the underline decoration from all links (a
elements), and adding an underline decoration when the mouse hovers over the link.
line-height
: This property is used to specify the vertical spacing between lines of text. You can use a unit such as pixels or ems. For example:
p { line-height: 1.5em; }
In this example, we’re setting the line height ofp
elements to 1.5 times the font size.
letter-spacing
: This property is used to specify the spacing between characters. You can use a unit such as pixels or ems. For example:
h2 { letter-spacing: 1px; }
In this example, we’re adding 1 pixel of spacing between characters inh2
elements.
These are just a few of the many CSS text properties available for styling text on web pages.