How to Create Drop Caps for the Text
If you want to give an original style to your Website, you can read this snippet and create a drop cap style for your texts via CSS first-letter pseudo element.
A drop cap is a style where the first character of the first paragraph is larger and takes up several lines of the text or the first few sentences. It is generally used in books and newspaper articles, but you can be more imaginative and use it for your Website, giving it an original style.
It’s easy to do, so let’s try together.
Create HTML
- Use the HTML
<p>tag and give it a class named "drop-cap".
How to create an HTML <p> tag and give it a class name "drop-cap"?
<p class="drop-cap">
France is a beautiful country, filled to the brim with delicious wines, and tons of romance. So it’s no surprise that many people want to visit France more than any other country in the world, according to the United Nations World Tourism Organization. In 2017, France welcomed 86.9 million people. La vie est belle!
</p>Add CSS
- Style the
<p>tag with the font-family, font-size and width properties. Also, add the margin property to create space around the text by choosing the “auto” value, which is the default value of this property. - Target the first letter of the paragraph by using the CSS first-letter pseudo-element, which is used to give a style to the first letter of the text. Add color and specify the
<span class="property">margin</span>and line-height properties. - Set the size with the
<span class="property">font-size</span>property. The size of the first letter must be much larger than the size of others. - Use the float property to define on which side of the container the element should be placed, and choose the “left” value, in order to move the letter to the left.
How to style an HTML element using CSS font-family, font-size, width and margin properties?
p {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 1.3em;
width: 80%;
margin: 0 auto;
}
p::first-letter {
color: #A52A2A;
float: left;
font-size: 5em;
margin: 0 .1em 0 0;
line-height: 0.85;
}Now let’s try some examples.
Example of creating a drop cap:
AN example of How to create drop caps for the text
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
p {
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 1.3em;
width: 80%;
margin: 0 auto;
}
p::first-letter {
color: #A52A2A;
float: left;
font-size: 5em;
margin: 0 .1em 0 0;
line-height: 0.85;
}
</style>
</head>
<body>
<p class="drop-cap">
France is a beautiful country, filled to the brim with delicious wines, and tons of romance. So it’s no surprise that many people want to visit France more than any other country in the world, according to the United Nations World Tourism Organization. In 2017, France welcomed 86.9 million people. La vie est belle!
</p>
</body>
</html>Result
<div class="demo px-2.5 mt-1 mb-5 not-prose"> France is a beautiful country, filled to the brim with delicious wines, and tons of romance. So it’s no surprise that many people want to visit France more than any other country in the world, according to the United Nations World Tourism Organization. In 2017, France welcomed 86.9 million people. La vie est belle!
</div>You can also create a border around the first letter by using the CSS border property.
Example of creating a drop cap with a border around it:
AN example of How to create drop caps for the text using CSS border property
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<style>
p {
font-family: New Century Schoolbook;
font-size: 1.3em;
width: 80%;
margin: 0 auto;
}
p::first-letter {
color: #483D8B;
float: left;
font-size: 5em;
border: 2px solid;
border-radius: 5px;
margin: 0 .1em 0 0;
line-height: 0.85;
}
</style>
</head>
<body>
<p class="drop-cap">
France is a beautiful country, filled to the brim with delicious wines, and tons of romance. So it’s no surprise that many people want to visit France more than any other country in the world, according to the United Nations World Tourism Organization. In 2017, France welcomed 86.9 million people. La vie est belle!
</p>
</body>
</html>