Open In App

Create Description List Component Using React and Tailwind CSS

Last Updated : 03 Oct, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

A description list is an elementary method to show key-value pairs, where a term and its definition are presented side by side. In this article, we will see the way of styling and implementing it as a component in a React Project using Tailwind CSS.

Prerequisites

Approach to Create Description List Component

  • Integrate Tailwind CSS into the project.
  • Build the description list component that dynamically accepts data as props.
  • Style the component using Tailwind CSS to ensure it is responsive.
  • Display the terms and their definitions in a clean, modern UI format.

Steps to Create Description List Component

Step 1: Set up the project using the command.

npm create vite@latest my-project 
cd my-project
npm install

Step 2: Install Tailwind CSS using the command.

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

Step 3: Configure the tailwind paths in your tailwind.config.js file.

/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}

Step 4: Add tailwind directives to your .src/ index.css file.

@tailwind base;
@tailwind components;
@tailwind utilities;

Folder Structure

Folder Structure

Updated Dependencies

 "dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1"
},

Example: In this example, we will create the description list component using react and tailwind CSS, remove all code in .src/App.css

JavaScript
// App.jsx

import React from 'react';

const App = () => {
    return (
        <div className='w-1/2 bg-black'>
            <div className="px-4 sm:px-0">
                <h3 className="text-base font-semibold leading-7 text-white 
                dark:text-gray-100">Applicant Information</h3>
                <p className="mt-1 max-w-2xl text-sm leading-6 text-gray-400 
                dark:text-gray-400">Personal details and application.</p>
            </div>
            <div className="mt-6 border-t border-gray-700 dark:border-gray-700">
                <dl className="divide-y divide-gray-700 dark:divide-gray-700">
                    <div className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
                        <dt className="text-sm font-medium leading-6 text-white 
                        dark:text-gray-100">Full name</dt>
                        <dd className="mt-1 text-sm leading-6 text-gray-400 
                        dark:text-gray-300 sm:col-span-2 sm:mt-0">Divyanshu Raj</dd>
                    </div>
                    <div className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
                        <dt className="text-sm font-medium leading-6 text-white 
                        dark:text-gray-100">Application for</dt>
                        <dd className="mt-1 text-sm leading-6 text-gray-400 
                        dark:text-gray-300 sm:col-span-2 sm:mt-0">MERN Stack Developer
                        </dd>
                    </div>
                    <div className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
                        <dt className="text-sm font-medium leading-6 text-white
                        dark:text-gray-100">Email address</dt>
                        <dd className="mt-1 text-sm leading-6 text-gray-400 
                        dark:text-gray-300 sm:col-span-2 sm:mt-0">example@gmail.com</dd>
                    </div>
                    <div className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
                        <dt className="text-sm font-medium leading-6 text-white 
                        dark:text-gray-100">Salary expectation</dt>
                        <dd className="mt-1 text-sm leading-6 text-gray-400 
                        dark:text-gray-300 sm:col-span-2 sm:mt-0">$80,000</dd>
                    </div>
                    <div className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
                        <dt className="text-sm font-medium leading-6 text-white 
                        dark:text-gray-100">About</dt>
                        <dd className="mt-1 text-sm leading-6 text-gray-400
                        dark:text-gray-300 sm:col-span-2 sm:mt-0">
                        Hey, I am a final year student searching for a 
                        Software Developer role!</dd>
                    </div>
                    <div className="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0">
                        <dt className="text-sm font-medium leading-6 text-white
                        dark:text-gray-100">Attachments</dt>
                        <dd className="mt-2 text-sm text-gray-900 dark:text-gray-300 
                        sm:col-span-2 sm:mt-0">
                            <ul role="list" className="divide-y divide-gray-700 
                            dark:divide-gray-700 rounded-md border border-gray-700
                            dark:border-gray-700">
                                <li className="flex items-center justify-between
                                py-4 pl-4 pr-5 text-sm leading-6">
                                    <div className="flex w-0 flex-1 items-center">
                                        <svg className="h-5 w-5 flex-shrink-0 
                                        text-gray-400 dark:text-gray-300" 
                                        viewBox="0 0 20 20" fill="currentColor" 
                                        aria-hidden="true">
                                            <path fillRule="evenodd" 
                                            d="M15.621 4.379a3 3 0 00-4.242 0l-7 
                                            7a3 3 0 004.241 4.243h.001l.497-.5a.75.75 
                                            0 011.064 1.057l-.498.501-.002.002a4.5 4.5
                                            0 01-6.364-6.364l7-7a4.5 4.5 0 016.368 
                                            6.36l-3.455 3.553A2.625 2.625 0 119.52 
                                            9.52l3.45-3.451a.75.75 0 111.061 1.06l-3.45 
                                            3.451a1.125 1.125 0 001.587 
                                            1.595l3.454-3.553a3 3 0 000-4.242z" 
                                            clipRule="evenodd" />
                                        </svg>
                                        <div className="ml-4 flex min-w-0 flex-1 gap-2">
                                            <span className="truncate font-medium 
                                            text-white">resume_MERN Stack_developer.
                                            pdf
                                            </span>
                                            <span className="flex-shrink-0 
                                            text-gray-400
                                            dark:text-gray-300">2.4mb</span>
                                        </div>
                                    </div>
                                    <div className="ml-4 flex-shrink-0">
                                        <a href="#" className="font-medium 
                                        text-indigo-600 hover:text-indigo-500 
                                        dark:text-indigo-400">Download</a>
                                    </div>
                                </li>
                                <li className="flex items-center justify-between 
                                py-4 pl-4 pr-5 text-sm leading-6">
                                    <div className="flex w-0 flex-1 items-center">
                                        <svg className="h-5 w-5 flex-shrink-0 
                                        text-gray-400 dark:text-gray-300" 
                                        viewBox="0 0 20 20" fill="currentColor" 
                                        aria-hidden="true">
                                            <path fillRule="evenodd" d="M15.621 
                                            4.379a3 3 0 00-4.242 0l-7 7a3 3 0 
                                            004.241 4.243h.001l.497-.5a.75.75
                                            0 011.064 1.057l-.498.501-.002.002a4.5 
                                            4.5 0 01-6.364-6.364l7-7a4.5 4.5 0 
                                            016.368 6.36l-3.455 3.553A2.625 2.625 
                                            0 119.52 9.52l3.45-3.451a.75.75 0 
                                            111.061 1.06l-3.45 3.451a1.125 1.125 
                                            0 001.587 1.595l3.454-3.553a3 3 0
                                            000-4.242z" clipRule="evenodd" />
                                        </svg>
                                        <div className="ml-4 flex min-w-0 flex-1 
                                        gap-2">
                                            <span className="truncate font-medium 
                                            text-white">coverletter_MERN Stack_developer
                                            .pdf</span>
                                            <span className="flex-shrink-0 text-gray-400
                                            dark:text-gray-300">4.5mb</span>
                                        </div>
                                    </div>
                                    <div className="ml-4 flex-shrink-0">
                                        <a href="#" className="font-medium 
                                        text-indigo-600 hover:text-indigo-500 
                                        dark:text-indigo-400">Download</a>
                                    </div>
                                </li>
                            </ul>
                        </dd>
                    </div>
                </dl>
            </div>
        </div>
    );
};

export default App;

To start the Application run the following command.

npm run dev

Output:

Screenshot-2024-10-01-211536
Description List Component Using React and Tailwind CSS

Next Article

Similar Reads