🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to CSS Notes
Topic #87

Text


Pseudo-elements for Text

Pseudo-elements for text, allow you to style specific parts of text content, such as the first line or first letter.


The CSS ::first-line Pseudo-element

The ::first-line pseudo-element is used to add a special style to the first line of a text.

Note: The ::first-line pseudo-element can only be applied to block-level elements.

Example

p::first-line
{

color: red;
  font-variant: small-caps;

font-size: 19px;

}

The CSS ::first-letter Pseudo-element

The ::first-letter pseudo-element is used to add a special style to the first letter of a text.

Note: The ::first-letter pseudo-element can only be applied to block-level elements.

Example

p::first-letter
{

color: red;

font-size: xx-large;

}

Pseudo-elements and HTML Classes

Pseudo-elements can easily be combined with HTML classes.

Example

p.intro::first-letter {
  color: #ff0000;

font-size: 200%;
}

Multiple Pseudo-elements

Several pseudo-elements can also be combined.

In the following example, the first letter of

elements will be red and in an xx-large font size. The rest of the first line will be blue and in small-caps. The rest of the paragraph will be in the default font size and color:

Example

p::first-letter
{

  color: red;

  font-size: xx-large;

}

p::first-line
{

color: blue;

font-variant: small-caps;

}

Want to go beyond the notes?

Join CodingNow 2.0's CSS course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Text – FAQs

Quick answers about learning Text in CSS.

This free note from CodingNow 2.0 explains Text in CSS — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every CSS topic on CodingNow 2.0, including Text, is 100% free with no signup required.
With focused practice, most students grasp Text in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now