Skip to content

UI Framework Integration with DaisyUI

In Lesson 10, we used Tailwind utilities to decide how our resource finder should adapt to different screen sizes. We also kept the layout rules separate from the components displaying the content.

Let’s look inside those components now. Our buttons repeat classes for borders, padding, colours, and hover styles. What if we could give a button a shared appearance with a class such as btn, then describe its purpose with btn-primary?

In this lesson, we’ll add DaisyUI 5 to our existing Tailwind CSS 4 setup. We’ll update the shared card and the buttons in Resource Details, then explore how themes affect their appearance.

At the end of this class, you should be able to…

  • Install and configure DaisyUI in a React project that uses Tailwind 4.
  • Apply DaisyUI component classes to existing JSX.
  • Enable built-in themes and apply one with data-theme.
  • Distinguish fixed colour utilities from theme-based colour roles.
  • Preserve responsive layout and semantic HTML while refactoring styles.
  • Explain one benefit and one trade-off of using a component library.
  • The page keeps its stacked, medium, and large-screen arrangements.
  • All three cards share the updated appearance through our Card component.
  • The existing Details buttons use DaisyUI styles.
  • Changing the selected theme changes the page surfaces and the refactored components.

We’re working on appearance. The starter’s buttons do not yet copy an email address, open a map, or filter the results. Adding CSS classes won’t implement those actions.

We’ve been writing React components: functions such as Card that return JSX and accept props.

DaisyUI provides CSS component classes, such as card and btn, that we apply to HTML elements. We can use those classes inside our React components. We don’t need to import a DaisyUI React Button to style a <button>.

<button type="button" className="btn btn-primary">
Open map
</button>

Here, btn supplies the button styling and btn-primary selects its primary colour treatment. We still choose the HTML element, its text, its type, and any behaviour. See the DaisyUI button reference.

We’ll keep three responsibilities in view:

Responsibility Where it belongs in our example
Grid and responsive spans PageLayout.jsx and the wrappers in App.jsx
Shared card appearance Card.jsx
Button appearance The existing buttons in Details.jsx
Theme selection The outer element in PageLayout.jsx

A theme gives colour roles their values. For example, bg-base-100 uses a theme’s base surface colour, while text-base-content uses its corresponding content colour. A fixed utility such as bg-white continues to mean white even when we choose a dark theme.

This is why installing a library won’t automatically make every existing style respond to a theme. We’ll need to decide which fixed colours to replace. DaisyUI’s colour reference describes these roles.

Shared classes can reduce repeated styling decisions and help components look consistent. They also give us a visual design to work within. If we need a very specific appearance, we may spend time adjusting that design.

We still need to preserve labels, headings, button semantics, and visible keyboard focus. A styled control is only one part of a usable interface.


Grab the starter kit code for your Workbook by running the following in the VS Code terminal at the root of your workbook.

Terminal window
pnpm dlx tiged --disable-cache --force DG-InClass/SDEV-2150-A01-Sep-2026/sk/day-11/example/lesson-11-starter ./src/lesson-11

If you already have today’s starter, continue with that copy. From your workbook root, run:

Terminal window
cd src/lesson-11/frontend
pnpm install
pnpm dev

Open the URL printed by Vite. The components use hard-coded resource data, so we don’t need the backend for this activity.

The file paths below start inside src/lesson-11/frontend. Use the active children implementation in PageLayout.jsx; the starter also contains commented-out alternatives that we won’t use.

In the diffs below, lines marked - are removed and lines marked + are added. Unmarked lines provide context. Make the changes without copying the diff markers into your files.

  1. Check the existing layout.

    Try viewport widths of 390px, 800px, and 1280px in DevTools. The starter should stack the cards on the narrow screen, put Filters above Results and Details at the medium width, and place all three beside each other at the large width.

    Open App.jsx and find the md:col-span-* and lg:col-span-* classes. Keep those wrappers and classes throughout this activity.

  2. Install DaisyUI in the frontend.

    Stop Vite with Ctrl+C, then run these commands from the frontend directory:

    Terminal window
    pnpm add -D daisyui@5
    pnpm dev

    Check package.json. DaisyUI should now appear in devDependencies. It supplies styles during the build, alongside our Tailwind tooling.

  3. Register the plugin and enable our themes.

    In src/index.css, keep the Tailwind import and add the plugin block immediately after it:

    src/index.css
    @import "tailwindcss";
    @plugin "daisyui" {
    themes: light --default, dark, cupcake;
    }
    :root {
    font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
    line-height: 1.5;
    font-weight: 400;
    color-scheme: light;

    Keep the existing :root font and rendering declarations below this block, but remove its color-scheme: light; declaration so we aren’t forcing a light colour scheme while experimenting with themes.

    We’ve enabled three themes and made light the default. The theme names we use later must be included here. Refer to the DaisyUI Vite installation guide and theme configuration when checking your setup.

  4. Verify the styles with an existing button.

    In Details.jsx, replace the className on the Open map button:

    src/components/Details.jsx
    <button
    type="button"
    className="rounded border border-sky-600 px-3 py-2 text-sm font-semibold text-sky-700 hover:bg-sky-50"
    className="btn btn-primary btn-sm"
    >
    Open map
    </button>

    The button should now have DaisyUI’s primary button appearance. btn-sm chooses a smaller size.

    If it still looks unstyled, check that you installed the dependency in frontend, saved index.css, and kept its import in main.jsx. Restart Vite if necessary before continuing.

  5. Apply a theme to the page.

    Add the theme constant and update the outer wrapper and header in the active PageLayout function. The grid classes and children remain in place.

    src/components/layout/PageLayout.jsx
    export default function PageLayout({ header, children }) { //({ header, left, middle, right }) {
    const theme = 'light';
    return (
    <div className="min-h-screen bg-gray-100">
    <header className="border-b border-sky-600 bg-white px-6 py-4">
    <div data-theme={theme} className="min-h-screen bg-base-200 text-base-content">
    <header className="border-b border-base-300 bg-base-100 px-6 py-4">
    {header}
    </header>
    <main className="mx-auto grid max-w-7xl grid-cols-1 gap-4 px-6 py-6 md:grid-cols-3">
    {children}
    </main>

    We’re placing data-theme on the React layout so it applies to that element and its descendants. It can also be placed on the document’s <html> element when a whole-document theme is appropriate; the layout is a convenient choice for this exercise.

    Temporarily change the constant to 'dark'. The page background and header surface should change, but the cards are still white. Notice that the cards still have bg-white in their own markup. Restore 'light' while we refactor them.

  6. Update the shared card.

    In Card.jsx, replace the classes on the section, header, and heading:

    src/components/ui/Card.jsx
    export default function Card({ title, children }) {
    return (
    <section className="h-full rounded border border-gray-200 bg-white shadow-sm">
    <header className="flex items-center justify-between border-b border-gray-200 px-4 py-3">
    <h2 className="leading-relaxed font-bold text-sm text-gray-900">{title}</h2>
    <section className="card h-full border border-base-300 bg-base-100 text-base-content shadow-sm">
    <header className="border-b border-base-300 px-4 py-3">
    <h2 className="card-title text-sm">{title}</h2>
    </header>
    <div>
    {children}
    </div>
    </section>
    );
    }

    All three cards should update because they already use this shared component. Its title and children props haven’t changed.

    card supplies the component styling, and card-title styles its heading. We retain h-full, the border, and our spacing utilities for this layout. The children already provide their own padding, so we aren’t adding another padded body around them. Compare this with the examples in the DaisyUI card reference.

  7. Finish the Details buttons and colours.

    In Details.jsx, update the final button container and the Copy email button. The Open map button already has its new classes from our earlier check.

    src/components/Details.jsx
    <div className="flex gap-2 border-t border-gray-200 px-4 py-3">
    <div className="flex flex-wrap gap-2 border-t border-base-300 px-4 py-3">
    <button
    type="button"
    className="rounded border border-gray-300 px-3 py-2 text-sm font-semibold text-gray-700 hover:bg-gray-50"
    className="btn btn-outline btn-sm"
    >
    Copy email
    </button>
    <button
    type="button"
    className="btn btn-primary btn-sm"
    >
    Open map
    </button>
    </div>

    The buttons now share a size while retaining different visual treatments. flex-wrap lets them wrap when space is limited.

    Next, update the heading and summary in the same file:

    src/components/Details.jsx
    <h2 className="text-base font-semibold text-gray-900">Peer Tutoring Centre</h2>
    <p className="text-sm text-gray-500">Drop-in tutoring and study support.</p>
    <h2 className="text-base font-semibold text-base-content">Peer Tutoring Centre</h2>
    <p className="text-sm text-base-content/80">Drop-in tutoring and study support.</p>

    Apply the same idea to the description list. Here’s the change for Category:

    src/components/Details.jsx
    <dl className="grid grid-cols-12 gap-y-2 text-sm">
    <dt className="col-span-4 font-semibold text-gray-700">Category</dt>
    <dd className="col-span-8 text-gray-600">Academic</dd>
    <dt className="col-span-4 font-semibold text-base-content">Category</dt>
    <dd className="col-span-8 text-base-content/80">Academic</dd>

    Repeat those class replacements for Location, Hours, and Contact: change text-gray-700 to text-base-content on each <dt>, and text-gray-600 to text-base-content/80 on each <dd>. Keep the other classes and all the text.

    The /80 modifier makes the content colour partially transparent. Check that the resulting text remains readable on the selected surface.

    In Header.jsx, update the directory heading and tagline so they follow the theme as well:

    src/components/Header.jsx
    <h1 className="text-xl font-semibold text-sky-600">NAIT Resource Directory</h1>
    <p className="text-sm text-gray-500">
    <h1 className="text-xl font-semibold text-primary">NAIT Resource Directory</h1>
    <p className="text-sm text-base-content/80">
    {tagline ? tagline : 'Find student support services, labs, and campus resources.'}
    </p>
  8. Compare the enabled themes.

    In PageLayout.jsx, change the theme constant to 'dark', then 'cupcake', saving after each change.

    The page surfaces, card headings, Details text, and Details buttons should respond. We haven’t changed their content or added React state.

    Look at Filters and Results as well. Their card shells respond, but some content still uses fixed gray, sky, or emerald colours. A theme doesn’t rewrite those classes. That remaining migration is a useful next exercise; don’t assume the whole page is ready for dark mode yet.

    Return the constant to 'light' for the completed guided example.

  9. Verify what we kept.

    Check the page at 390px, 767px, 768px, 1023px, 1024px, and 1280px. The layout should still transition at the same points as before.

    Tab through the controls. Check visible focus, readable labels, and text wrapping. Keep type="button" on the Details buttons so they retain their intended button semantics.

    Finally, run pnpm build from the frontend directory. This checks that the JSX and CSS configuration compile; it doesn’t replace the browser checks.

We’ve introduced a component library through the existing CSS setup, changed all three card shells through one React component, and simplified the Details buttons. Tailwind still controls the page layout and spacing.

Before moving on, compare the original Open map classes with btn btn-primary btn-sm. Which decisions did we hand to the library? Which decisions are still ours?


The starter’s homework.md continues your Users and Posts project from Lesson 10. Integrate DaisyUI into that existing project while preserving its responsive layout and data rendering.

Your solution should:

  • Use DaisyUI 5 with the existing Tailwind 4 setup.
  • Enable the themes you want to compare in the existing CSS entry file.
  • Select a theme with data-theme in your React layout.
  • Refactor at least one existing presentation component using DaisyUI classes.
  • Remove styling utilities that the new component classes replace, while retaining useful layout and spacing utilities.
  • Preserve content, labels, semantic elements, keyboard focus, and all three responsive arrangements.

Keep the work focused on styling. Don’t add new data sources, state, event handlers, or custom CSS files.

In your homework’s README.md, identify the component you refactored, explain your theme choice, and describe one benefit and one drawback you observed. Check the result at the same viewport widths used in the walkthrough.

Return to today’s resource finder and finish migrating Filters and Results to theme-based styles. Use the DaisyUI documentation to choose suitable input, checkbox, button, and badge classes. Preserve the existing label associations and button types.

Compare light and dark again. Your goal is readable content, visible focus, and consistent surfaces throughout the page. Identify any fixed colours that you deliberately kept and explain why they should stay the same across themes.