How to Add Text Shadow in Tailwind CSS?
Last Updated :
10 Oct, 2024
Adding a text shadow in Tailwind CSS is useful for making text for creating visual effects like glows and embossed or debossed effects. Tailwind CSS does not provide text shadow utilities out of the box but it allows you to easily extend its functionality to add custom utilities. In this article, we will explore how to add a text shadow in a project using Tailwind CSS.
Approach
- Begin the project by creating a React application and installing Tailwind CSS along with its dependencies.
- Modify the
tailwind.config.js
file to include a custom plugin. Within this plugin, define the text-shadow styles you want to support, such as various shadow sizes and colors. - Once the custom utilities are defined, you can apply them directly in your React components using the classes you created, allowing for easy integration of text shadows throughout your application.
- Finally, run the application to see the text-shadow effects in action, making adjustments as needed to perfect the styles.
Prerequisites
Steps To Add Text Shadow
Step 1: Set up a React Application
npx create-react-app react-app
cd react-app
Step 2: Install Tailwind CSS using the command
npm install -D tailwindcss postcss autoprefixernpx tailwindcss init -p
Step 3: Configure the tailwind paths in your tailwind.config.js file
module.exports = {
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
extend: {
colors: {
primaryGreen: "#4CAF50", // Green
primaryBlack: "#000000", // Black
primaryWhite: "#FFFFFF", // White
}
},
},
plugins: [],
}
Step 4: Add tailwind directives to your index.css file
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
margin: 0;
font-family: 'Times New Roman', Times, serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
Project Structure:
Project structureUpdated Dependencies:
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}
Example: This example demonstrates the creation of text shadow using React and Tailwind CSS
JavaScript
// App.js
import React, { useState } from "react";
function App() {
return (
<div className="flex items-center justify-center min-h-screen bg-green-100">
<ul class="space-y-8 w-full h-96 p-8 flex items-center justify-center
gap-2 flex-col bg-inherit rounded-xl">
<li class="[text-shadow:_0_2px_4px_rgb(99_102_241_/_0.8)]
text-indigo-600 text-xl md:text-2xl leading-snug
font-manrope font-extrabold">Text Shadow: Small
</li>
<li class="[text-shadow:_0_4px_4px_rgb(99_102_241_/_0.8)]
text-indigo-600 text-xl md:text-2xl leading-snug
font-manrope font-extrabold">Text Shadow: Default
</li>
<li class="[text-shadow:_0_8px_8px_rgb(99_102_241_/_0.8)]
text-indigo-600 text-xl md:text-2xl leading-snug
font-manrope font-extrabold">Text Shadow: Large
</li>
<li class="[text-shadow:_0_4px_8px_#00BCD4] text-[#00BCD4]
text-xl md:text-2xl leading-snug font-manrope
font-extrabold">Text Shadow: Arbitrary (Custom Color)
</li>
<li class="[text-shadow:_0_4px_8px_rgba(14_165_223_/_0.5)]
text-sky-400 text-xl md:text-2xl leading-snug
font-manrope font-extrabold"> Text Shadow: Arbitrary
(Tailwind CSS Color)
</li>
</ul>
</div>
);
}
export default App;
Step 4: Run the Application
npm start
Output:
outputConclusion
This article showcases the flexibility of Tailwind CSS and its extensibility through custom utilities such as adding text shadows. By extending the default configuration we can introduce new styling options that are not available out of the box. We also demonstrated how JavaScript can be integrated with Tailwind to dynamically manipulate styles and adding interactivity to a static webpage.
Similar Reads
How To Add Custom Box Shadow In Tailwind CSS? Tailwind CSS is a utility-focused CSS framework. Offers a wide range of design utilities. It does include predefined shading, however, for unique design needs, you might want a custom box shadow that goes beyond the default. in this article, you will learn how to extend Tailwind's default shadow and
3 min read
How to Add Tailwind CSS to HTML ? Tailwind CSS is a utility-first framework offering pre-defined classes for rapid styling of HTML elements. It simplifies customization and accelerates web development workflows.Integration Options:CDN Integration: Quickly add Tailwind CSS via a CDN link in the <head> of your HTML.Using npm: In
3 min read
How to Apply Inset to Box Shadow in Tailwind CSS? In web development, shadows play a significant role in attracting user attention. By applying shadows to elements on our web pages, we can enhance their visual appearance and attract the user's focus. In Tailwind CSS, we can apply an insert box shadow by using the "shadow-inner" utility class.Approa
2 min read
How to Add Shadow in CSS? Shadows in CSS can be used to create depth and visual interest by adding the effect that simulates the shadow of an element. It can be applied to both the text and block elements to enhance the design of the web pages. CSS can provide several properties to achieve different shadow effects, including
4 min read
How to Add New Colors in Tailwind CSS ? Tailwind CSS is a popular utility-first CSS framework that offers a wide range of pre-designed styles and classes to simplify the process of styling web applications. However, the default set of colors provided by Tailwind may not always meet the requirements of your project. In such cases, you may
4 min read
How to Add Shadow to Image in CSS ? Adding shadow to an image can enhance its visual appeal and make it stand out on your webpage. In this article, we will explore various approaches to add shadow to an image using CSS. Table of Content Add Shadow on Image using box-shadow PropertyAdd Shadow on Image on HoverAdd Shadow on Image using
2 min read
How to Set Text Color in RGBA in Tailwind CSS ? In this article, we will change the color of text to rgba(0, 0, 0, 0.54) which is an RGB color format with an added parameter alpha that tells the opacity of the color. In this article, we are going to learn how we can achieve the text color of rgba(0, 0, 0, 0.54) in Tailwind CSS and hence, change t
3 min read
How to Add Shadow to Button in CSS ? This article will show you how to add shadow to a button using CSS. Button shadow can enhance its visual appeal and make it stand out on your webpage. This article will cover various approaches to adding shadow to a button using CSS. Table of Content Add Shadow on button using box-shadow PropertyAdd
3 min read
How to Add Shadow to Text using CSS? The text-shadow property is used to add shadow to the text. The text-shadow property creates text shadows, specifying horizontal/vertical offsets, blur radius, and color for depth and emphasis.Note: We can customize text shadow by changing position, blur, and color for improved appearance and visual
1 min read
How to Add Text Outline with CSS? Since CSS does not provide a direct text-outline property, the CSS text-shadow property is used to create an outline effect around text by adding multiple shadows with offsets.1. Using text-shadow PropertyThe text-shadow property is commonly used to add shadows to text, by applying multiple shadows
1 min read