Encodera

Thanks for reading!

Donate to the site — we work hard for you.

Contents

Buttons

A button is the most common interface component, and in daisyUI it starts with the btn class. You can put it on a <button>, on an <a> link and even on an <input type="submit"> — they will all look the same.

A simple button

<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
 
<button class="btn">Log in</button>

A grey button with padding, rounded corners and a response to hover and press. Color comes from a modifier: btn-primary, btn-secondary, btn-error and the others from the colors lesson.

Styles

Besides the regular fill, a button has several drawing styles:

<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
 
<div class="flex flex-wrap gap-2 p-4">
  <button class="btn btn-primary">Enroll</button>
  <button class="btn btn-primary btn-outline">Outline</button>
  <button class="btn btn-primary btn-soft">Soft</button>
  <button class="btn btn-primary btn-dash">Dash</button>
  <button class="btn btn-ghost">Ghost</button>
  <button class="btn btn-link">Link</button>
</div>
ModifierLookWhen to use
no styleSolid fillThe main action
btn-outlineBorder onlyA secondary action
btn-softPale fillQuiet buttons in panels
btn-dashDashed border"Add", empty slots
btn-ghostNo background until hoverButtons in menus and headers
btn-linkLike a linkAn action inside text

Sizes and shape

Sizes: btn-xs, btn-sm, btn-lg, btn-xl. Shape modifiers change the proportions:

<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
 
<div class="flex flex-wrap items-center gap-2 p-4">
  <button class="btn btn-sm">Small</button>
  <button class="btn btn-lg">Large</button>
  <button class="btn btn-circle">+</button>
  <button class="btn btn-square">×</button>
  <button class="btn btn-primary btn-wide">Wide</button>
</div>
<div class="p-4">
  <button class="btn btn-primary btn-block">Full width</button>
</div>

btn-circle and btn-square make the button round or square — for icons. btn-wide stretches it to a fixed large width, and btn-block to the full width of its parent.

A disabled button uses the regular disabled attribute: daisyUI makes it pale by itself. For a link that should look like a button, use <a class="btn">:

<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css">
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
 
<div class="flex gap-2 p-4">
  <a href="#courses" class="btn btn-primary">All courses</a>
  <button class="btn" disabled>Course closed</button>
</div>

On the left is a link that looks like a button, on the right a pale button you cannot press. Pick the tag by meaning: going to another page is an <a>, an action on the page is a <button>.

Common mistake

Putting btn-disabled on a link and assuming it is disabled. The class makes it pale and blocks mouse clicks, but from the keyboard — with Tab and Enter — the link still opens, and screen readers announce it as a regular link. Use the disabled attribute on a <button>, and for an inactive link remove the href or replace it with text.

Thanks for reading!

Donate to the site — we work hard for you.