Code Snippet
Drop Caps
Cross-browser way (extra markup)
Just wrap the first character of the paragraph in a span, then target the span with CSS and style away.
<p>
<span class="firstcharacter">L</span> orem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tristique lobortis orci ac lacinia. Fusce eu purus eget diam vehicula auctor nec eu elit. Morbi consequat facilisis orci vel malesuada. Donec ultrices molestie sollicitudin. Aliquam pharetra libero enim. Donec et suscipit massa. Donec dui odio, dignissim non sodales et, tincidunt a sapien. Phasellus elit nibh, adipiscing sed blandit vel, interdum et arcu.
</p>
.firstcharacter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; }
CSS3 way (no extra markup)
Target the first character of the first paragraph using pseudo class selectors. No extra markup needed, but no IE < 9 support.
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tristique lobortis orci ac lacinia. Fusce eu purus eget diam vehicula auctor nec eu elit. Morbi consequat facilisis orci vel malesuada. Donec ultrices molestie sollicitudin. Aliquam pharetra libero enim. Donec et suscipit massa. Donec dui odio, dignissim non sodales et, tincidunt a sapien. Phasellus elit nibh, adipiscing sed blandit vel, interdum et arcu.
</p>
p:first-child:first-letter { float: left; color: #903; font-size: 75px; line-height: 60px; padding-top: 4px; padding-right: 8px; padding-left: 3px; font-family: Georgia; }
That’s a really nice funcionality, didn’t really know about the “first-letter”. Thanks for the tip!
Actually it kind of works in ie8. If the paragraph has nothing before it ( etc) then it will work…
The first option gives you more control. I tried the second and the only that got a drop cap was the footer text. This is a cool feature. Having come from a print design background, I missed drop caps. I used to make images for this purpose back in the day. This is sweet!
small but nice
Neat! I didn’t even think of using drop caps on a website, but now that I see it in action it could be very useful in a well-designed site.
This is awesome ! nice tips mate :)
Excellent snippet — I was having cross-browser issues with :first-letter, the span solution left me spic-n-pixel-perfect. Thanks!
Thank you very much for this tip.
This doesn’t seem to work, oh wow comment previews! King of Cascade, Chris Coyier!
Sorry ended up a douchebag comment whilst amazement took place.
Testing this in Chrome 13.0.782.220 m
That selector doesn’t seem to work. However i’m noticing other bugs with this build on the laptop also. Weird artifacts being left in browser when multiple tabs are open.
This steps helped me. Thanks for the tutorial :)
Thank you! It works!
BTW: are there any fonts that look particularly well and could be recommended to use in drop caps (apart from Georgia)?
DigWP
A book and blog co-authored by Jeff Starr and myself about the World's most popular publishing platform.
Quotes on Design
Design, like Art, can be an elusive word to define and an awfully fun thing to have opinions about.
HTML-Ipsum
One-click copy to clipboard access to Lorem Ipsum text that comes wrapped in a variety of HTML.
Bookshelf
Hey Chris, what books do you recommend? These, young fertile mind, these.