Styling First Letters with CSS ::first-letter

In this tutorial, we will learn how to style the first letters of the content with the help of by using the CSS ::first-letter selector? By Apurva Mathur Last updated : July 23, 2023

These are one of the common and very interesting ways of designing the parts of the specific elements. We must have seen on many WebPages the first letter of the content is displayed in a very artistic manner.

How to style first letters with CSS ::first-letter?

To style the first letters of the elements/content, you can use ::first-letter pseudo-element. The ::first-letter selector selects and styles the first letter of any element such as p, h1, h2, etc. i.e., you can add any style to the first letter of the content.

Syntax of CSS ::first-letter

Whenever you are using pseudo-element it is important to know that we always use this with the following syntax:

element::before, ::after, etc.

Observe that :: is used with pseudo-element (using double colons is important).

Syntax for styling first letter

The following is the syntax of styling the first letter of a specific element. Let the specific element is h2.

h2::first-letter {
  Property1: value;
  Property1: value;


The below-given example illustrates the CSS ::first-letter pseudo-element to style the first letter of an element.

         text-align: center;
         h1::first-letter {
         font-family: "Gill Sans Ultra Bold Condensed";
         font-size: 60px;
         color: greenyellow;
         text-shadow: 5px 8px 9px gold;
         color: red;
         font-family: "Book Antiqua";
         font-family: "Gill Sans Ultra Bold Condensed";
         font-size: 60px;
         text-shadow: 5px 8px 9px #b3d4fc;
         color: #4CAF50;
         font-family: "Lucida Console";
         font-size: 2cm;
      <h1> Include help welcomes you </h1>
      <h2>Our aim is to make you "an expert in Computer programming languages".</h2>
      <h3>IncludeHelp is a FREE site and will remain FREE in future as well</h3>

The output of the above code is:

Example: Styling First Letters with CSS

Example Code Explanation

If you see the code you'll observe that the property used in the CSS part is really basic the only concept you need to understand is the working of first-letter in the code, in the above code h1::first-letter will only and only apply the CSS properties to the first letter written inside h1 tag. If you have more than one h1 tag in the code then in that case it will style the first letter of all the h1 tags.

Just play with your imagination by giving more color/font/shadow property to the first-letter pseudo-element.

CSS Examples »

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.