Paulund

Learn How To Create Drop Cap Letters In CSS

In the tutorial today we are going to learn how we can use just CSS to create an old newspaper technique of making the first letter of a paragraph capital and drop into the paragraph.

Drop Capital

View the demo to see what we are going to create.

Demo

Old Way To Handle With CSS

You could always do this with CSS but you had to use a span tag on the first letter.

<p><span>L</span>orem ipsum dolor sit amet, consectetur adipiscing elit. Ut in metus nec mauris egestas laoreet. Integer vehicula velit non massa suscipit at porta sem commodo. Donec nibh lectus, vulputate a aliquet quis, sollicitudin eget metus. Nullam quis tellus nibh. Praesent fermentum risus sit amet turpis eleifend dapibus. Duis tellus leo, tempor sit amet ultricies viverra, mollis at quam. Suspendisse hendrerit sagittis risus nec faucibus. Nam urna magna, porta vitae tincidunt sit amet, blandit eget diam. Vivamus a ornare augue. Vivamus sapien sem, facilisis vitae molestie eget, tempus ut augue. Sed suscipit facilisis mi, eu laoreet est gravida eu. Nulla et arcu quam, pellentesque adipiscing felis. Nam pretium augue sed sapien malesuada tempor. Nulla facilisi. Donec eu tempor mi. Sed congue dolor risus, et ornare massa.</p>

Then you have to add a style to the span tag to create the drop capital.

p + span {
        display:block;
	float:left;
	font-family:Georgia;
	font-size: 310%;
	font-weight: bold;
	line-height: 90%;
	margin-right: 6px;
	margin-bottom:-2px;
	margin-top: 7px;
}

The problem with this technique is that you have to remember to add a span around the paragraph each time you want to create the drop capitals, in a CMS system when the user might not understand HTML then you won’t be able to add a span tag.

The way around this is to use CSS3 new property :first-letter.

CSS First Letter

CSS allows you to add a property :first-letter which as you can guess allows you to style the first letter of the element.

Therefore you can add this to all paragraph to create drop capitals on all paragraphs.

p:first-letter {
	display:block;
	float:left;
	font-family:Georgia;
	font-size: 310%;
	font-weight: bold;
	line-height: 90%;
	margin-right: 6px;
	margin-bottom:-2px;
	margin-top: 7px;
}

View the demo to see how this will style the different paragraphs.

Demo

Wix HTML5

Writen By Paul

Paulund is a website dedicated to writing tutorials and code snippets about Web Development, the main subjects are PHP, Wordpress, jQuery, CSS3 and HTML5.

Website: http://www.paulund.co.uk

Feedback

Anything to add?

  • Pingback: Learn How To Create Drop Cap Letters In CSS

  • jposwal

    but not supported in all browser…becoz its in css3..

  • http://www.cyberdesignz.com/services/web-designers web designers

    Hi PAUL.
    Nice post that describe in depth.
    Thanks for sharing your experience.

    • http://www.paulund.co.uk/ Paul

      Your welcome

  • http://www.logoblog.org/ Logo Design Company

    Interesting!! This css works really great! i just check on my blog and cap letter looks great!

  • http://www.newwebtemplates.net/ New Web Templates

    After using this css on my blog post, literally it looks great :) thanks for sharing.

    • http://www.paulund.co.uk/ Paul

      Your welcome.

  • Pingback: Twenty Top Advanced CSS Tutorials » HTML & CSS, Web Design » Design Festival