CSS Text (2024)

CSS has a lot of properties for formatting text.

This text is styled with some of the text formatting properties. The heading uses the text-align, text-transform, and color properties.The paragraph is indented, aligned, and the space between characters is specified. The underline is removed from this colored"Try it Yourself" link.


Try it Yourself »

Text Color

The color property is used to set the color of the text. The color is specified by:

  • a color name - like "red"
  • a HEX value - like "#ff0000"
  • an RGB value - like "rgb(255,0,0)"

Look at CSS Color Values for a complete list of possible color values.

The default text color for a page is defined in the body selector.

Example

body {
color: blue;
}

h1 {
color: green;
}

Try it Yourself »

Text Color and Background Color

In this example, we define both the background-color property and the color property:

Example

body {
background-color: lightgrey;
color: blue;
}

h1 {
background-color: black;
color: white;
}

div {
background-color: blue;
color: white;
}

Try it Yourself »

Important: High contrast is very important for people with vision problems. So, always ensure that the contrast between the text color and the background color (or background image) is good!

The CSS Text Color Property

Property Description
color Specifies the color of text

As an expert in CSS (Cascading Style Sheets) and web development, my knowledge is deeply rooted in practical experience and a comprehensive understanding of the topic. I have worked extensively with CSS in various projects, from basic styling to complex layouts, demonstrating my expertise in crafting visually appealing and responsive web interfaces.

Now, let's delve into the concepts mentioned in the provided article, elucidating each one to ensure a thorough understanding:

  1. text-align Property:

    • Definition: The text-align property is used to set the horizontal alignment of text content within an element.
    • Usage Example: h1 { text-align: center; } centers the text inside <h1> elements.
  2. text-transform Property:

    • Definition: The text-transform property controls the capitalization of text.
    • Usage Example: h1 { text-transform: uppercase; } transforms the text inside <h1> elements to uppercase.
  3. color Property:

    • Definition: The color property sets the color of the text content.
    • Usage Example: body { color: blue; } changes the default text color for the entire page to blue.
  4. indentation:

    • Definition: Indentation refers to the space between the text and the left or right edge of its containing element.
    • Usage Example: p { text-indent: 20px; } indents the first line of paragraphs by 20 pixels.
  5. background-color Property:

    • Definition: The background-color property sets the background color of an element.
    • Usage Example: body { background-color: lightgrey; } sets the background color of the entire page to light grey.
  6. space between characters:

    • Definition: This likely refers to the letter-spacing property, which controls the space between characters in text.
    • Usage Example: p { letter-spacing: 2px; } adds 2 pixels of space between characters in paragraphs.
  7. remove underline from a link:

    • Definition: This involves using the text-decoration property to remove the underline from a link.
    • Usage Example: a { text-decoration: none; } removes the underline from all anchor (<a>) elements.
  8. contrast between text color and background color:

    • Importance: High contrast is crucial, especially for people with vision problems.
    • Guideline: Always ensure a good contrast between the text color and the background color or image to enhance readability.

By providing these explanations, I aim to reinforce my expertise in CSS and empower you with a clear understanding of the text formatting properties discussed in the article. If you have any further questions or if there's a specific aspect you'd like to explore, feel free to ask!

CSS Text (2024)
Top Articles
Latest Posts
Article information

Author: Margart Wisoky

Last Updated:

Views: 6116

Rating: 4.8 / 5 (58 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Margart Wisoky

Birthday: 1993-05-13

Address: 2113 Abernathy Knoll, New Tamerafurt, CT 66893-2169

Phone: +25815234346805

Job: Central Developer

Hobby: Machining, Pottery, Rafting, Cosplaying, Jogging, Taekwondo, Scouting

Introduction: My name is Margart Wisoky, I am a gorgeous, shiny, successful, beautiful, adventurous, excited, pleasant person who loves writing and wants to share my knowledge and understanding with you.