Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
CSS shadows add depth and style to web elements, helping to create engaging, modern designs. By using shadows in CSS, you can enhance visual interest and highlight important parts of a page with just a few lines of code. CSS provides two main types of shadows: box shadows and text shadows. Box shadows add shadow effects around elements like divs and buttons, creating a sense of elevation or depth. Text shadows, on the other hand, enhance text by adding subtle or bold shadowing that can make it stand out on the page.
A shadow has been added to the text in the pictures above, but we can also add shadows to a box or an image. This gives us two kinds of shadows:
Text Shadow
Box Shadow
Let’s learn what they are in this article.
Text Shadow
Text shadows in CSS are a styling technique used to add a shadow effect behind text, which enhances its appearance and makes it stand out on a webpage. By adjusting the shadow’s color, blur, and positioning, you can create subtle depth or bold, eye-catching effects. Text shadows are commonly used to improve readability, create visual interest, and give text a more three-dimensional appearance.
To begin with, let’s see the code for the example shown below above.
Here, a simple shadow of the same colour is added to the text by only a horizontal and vertical shadow. So the shadow isn’t prominent. Let’s change the colour of the shadow and see how it looks.
Box Shadow
A box shadow in CSS is used to add shadow effects around an element’s frame, creating a sense of depth or highlighting. By customizing the shadow’s offset, blur, spread, and color, you can achieve subtle or dramatic effects to enhance the element’s appearance.
Parts of the box-shadow property
There are four box-shadow numbers to choose from:
offset-x: The horizontal shift of the shadow of the element. Positive values shift the shadow to the right, while negative values move it to the left.
offset-y: The perpendicular displacement of the shadow of the element. Positive values make the image smaller, while negative values make it larger.
blur-radius: The amount of blur that is used to produce the shadow. Higher values result in a softer, more dispersed shadow.
color: The tone of the shadow. This can be specified using keywords (for example, black, white), hexadecimal values (for example, #000000, #fffff), RGB or RGBA values (for example, rgb(0,0,0), rgba(255,255,255,0.5)), or HSL or HSLA values (for example, hsl(0,0%,0%), hsla(0,0%,100%)).
As the name suggests, a box shadow adds a shadow effect to a box, as shown below.
But how do we use CSS shadows in a box?
Adding shadows to a text and a box aren’t much different. All we need to do is add a horizontal and vertical shadow.
The last and exciting use of CSS shadows in texts is to add a border around them. To do that, we’ll add four shadows to the text - a negative and a positive horizontal and vertical shadow.
The inset keyword can be added before the other properties to add an inner shadow instead of an outer shadow. The example shown below will help us understand the difference between an inner and outer shadow.
Outlines in CSS are similar to borders but are drawn outside the element’s box, without affecting its layout or size. They are typically used to highlight elements, such as for focus states or accessibility, and can be styled with color, width, and style.
Cards
One final thing we’ll see before wrapping up is how to add paper-like cards using CSS.