Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

190
Vistas
::first-letter also styles first character

I have this Text:

p::first-letter {
  color: red;
}
<p>"Welcome!"</p>

but then i realized that also the " got styled.

I tried using ::before but that didn't work either:

p::first-letter {
  color: red;
}

p::before {
  content: '"';
}
<p>Welcome!"</p>

How could I manage to only style the first letter (In clean code)?

over 4 years ago · Santiago Trujillo
4 Respuestas
Responde la pregunta

0

Here is what I came up with after trying and thinking a bit of CSS/HTML principles:

I will be using display: inline-block; because ::first-letter requires a block for its content to work.

Please pay attention that I am using <span></span> tag and not <p></p> tag as the HTML W3 Consortium consider it as invalid html code. You can check your code about validity here

Take a look at the sandbox or at the live example here:

.quote span {
  display: inline-block;
}

.quote span::first-letter {
  color: red;
}
<q class="quote" cite="https://www.imdb.com/title/tt0062622/quotes/qt0396921"><span>This is a great quote</span></q>

More info on tags here:

  • see what is <q></q> tag is and how to use it;
  • see more about what is <span></span> (e.g. text wrapper to any text you want to display and style depending on your needs);
  • look through this to see what is the ::first-letter, how it works, and what is needed for it to work properly.
over 4 years ago · Santiago Trujillo Denunciar

0

p::first-letter, it will always style the first character, to style W put a span element like W then style the span.

over 4 years ago · Santiago Trujillo Denunciar

0

You can text-indent the paragraph and use a before positioned in absolute, but you have to manually set the indent that depends on text-size. It is not a super-clean solution: it is a "not so dirty" one.

p {
  text-indent: 5px;
}
p::first-letter {
  position:relative;
  color: red;
}

p::before {
  position:absolute;
  content: '"';
  left: 0;
}
<p>Welcome"</p>

over 4 years ago · Santiago Trujillo Denunciar

0

simply float the first character and use :after not :before

p::first-letter {
  color: red;
}

p::after {
  content: '"';
  float:left;
}
<p>Welcome!"</p>

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda