Nuestros voluntarios aún no han traducido este artículo al Español. ¡Únete a nosotros y ayúdanos a traducirlo!
También puedes leer el artículo en English (US).

The ::first-letter CSS pseudo-element applies styles to the first letter of the first line of a block-level element, but only when not preceded by other content (such as images or inline tables).

/* Selects the first letter of a <p> */
p::first-letter {
  font-size: 130%;
}

The first letter of an element is not always trivial to identify:

  • Punctuation that precedes or immediately follows the first letter is included in the match. Punctuation includes any Unicode character defined in the open (Ps), close (Pe), initial quote (Pi), final quote (Pf), and other punctuation (Po) classes.
  • Some languages have digraphs that are always capitalized together, like the IJ in Dutch. In these cases, both letters of the digraph should be matched by the ::first-letter pseudo-element. (This is poorly supported by browsers; see the browser compatibility table below.)
  • A combination of the ::before pseudo-element and the content property may inject some text at the beginning of the element. In that case, ::first-letter will match the first letter of this generated content.

CSS3 introduced the ::first-letter notation (with two colons) to distinguish pseudo-classes from pseudo-elements. Browsers also accept :first-letter, introduced in CSS2.

Allowable properties

Only a small subset of CSS properties can be used with the ::first-letter pseudo-element:

Syntax

/* CSS3 syntax */
::first-letter

/* CSS2 syntax */
:first-letter

Example

Make the first letter of every paragraph red and big.

HTML

<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
  ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
  dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est.</p>
<p>Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat.</p>
<p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut
  aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit
  esse molestie consequat.</p>
<p>-The beginning of a special punctuation mark.</p>
<p>_The beginning of a special punctuation mark.</p>
<p>"The beginning of a special punctuation mark.</p>
<p>'The beginning of a special punctuation mark.</p>
<p>*The beginning of a special punctuation mark.</p>
<p>#The beginning of a special punctuation mark.</p>
<p>「特殊的汉字标点符号开头。</p>
<p>《特殊的汉字标点符号开头。</p>
<p>“特殊的汉字标点符号开头。</p>

CSS

p::first-letter {
  color: red;
  font-size: 130%;
}

Result

Specifications

Specification Status Comment
CSS Pseudo-Elements Level 4
The definition of '::first-letter' in that specification.
Working Draft Generalizes allowed properties to typesetting, text decoration, inline layout properties, opacity, and box-shadow.
CSS Text Decoration Module Level 3
The definition of 'text-shadow with ::first-letter' in that specification.
Candidate Recommendation Allows the use of text-shadow with ::first-letter.
Selectors Level 3
The definition of '::first-letter' in that specification.
Recommendation Introduction of the two-colon syntax. Definition of edge-case behavior, such as in list items or with specific languages (e.g., the Dutch digraph IJ).
CSS Level 2 (Revision 1)
The definition of '::first-letter' in that specification.
Recommendation No change.
CSS Level 1
The definition of '::first-letter' in that specification.
Recommendation Initial definition, using the one-colon syntax.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung Internet
Basic supportChrome Full support 1
Full support 1
Full support 1
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
Edge Full support Yes
Full support Yes
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
Firefox Full support 1
Full support 1
Full support 1
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
IE Full support 9
Full support 9
Full support 5.5
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
Opera Full support 7
Full support 7
Full support 3.5
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
Safari Full support 1
Full support 1
Full support 1
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
WebView Android ? Chrome Android ? Edge Mobile Full support Yes
Full support Yes
Full support Yes
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
Firefox Android Full support 4
Full support 4
Full support 4
Alternate Name
Alternate Name Uses the non-standard name: :first-letter
Opera Android ? Safari iOS ? Samsung Internet Android ?
Support for the Dutch digraph IJChrome No support NoEdge No support NoFirefox No support No
Notes
No support No
Notes
Notes See bug 92176.
IE No support NoOpera No support NoSafari No support NoWebView Android ? Chrome Android ? Edge Mobile No support NoFirefox Android No support No
Notes
No support No
Notes
Notes See bug 92176.
Opera Android ? Safari iOS ? Samsung Internet Android No support No

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
See implementation notes.
See implementation notes.
Uses a non-standard name.
Uses a non-standard name.

See also

Etiquetas y colaboradores del documento

Última actualización por: jsartelle,