Text in CSS Language
Cascading Style Sheets (CSS) is a fundamental technology for web development that empowers developers to control the presentation of web content. One crucial aspect of web design is m
anipulating text, from adjusting fonts and colors to handling alignment and spacing. In this post, we will explore the various ways you can work with text in CSS, using practical examples to illustrate each concept.- Changing Font Family and Size:
One of the most common text-related tasks in CSS is modifying the font family and size. You can use thefont-family
property to specify the font, andfont-size
to set the text size. Here’s an example:
/* CSS */
body {
font-family: Arial, sans-serif;
font-size: 16px;
}
- Changing Text Color:
To change the color of text, you can use thecolor
property. You can specify colors using names, hex codes, or RGB values:
/* CSS */
p {
color: #FF5733; /* Hex code for a red color */
}
- Text Alignment:
To control text alignment within an element, you can use thetext-align
property. Here’s how you can align text to the center of a container:
/* CSS */
.center-text {
text-align: center;
}
- Text Decoration:
CSS allows you to add various decorations to text, such as underlines, overlines, and more. You can use thetext-decoration
property to apply these styles:
/* CSS */
a {
text-decoration: underline;
}
- Letter Spacing and Line Height:
You can adjust the space between letters and lines using theletter-spacing
andline-height
properties, respectively:
/* CSS */
h1 {
letter-spacing: 2px;
line-height: 1.5;
}
- Text Shadow:
To create a shadow effect behind your text, you can use thetext-shadow
property. The following example adds a shadow to the text:
/* CSS */
h2 {
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
}
- Text Transformation:
CSS allows you to change the capitalization of text using thetext-transform
property. For example, you can transform text to uppercase:
/* CSS */
button {
text-transform: uppercase;
}
- Text Overflow and Wrapping:
To control how text overflows its container and how it wraps to the next line, you can use properties likeoverflow
andwhite-space
:
/* CSS */
.ellipsis-text {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Discover more from PiEmbSysTech
Subscribe to get the latest posts sent to your email.