點燈坊

失くすものさえない今が強くなるチャンスよ

Simple Button with TailwindCSS

Sam Xiao's Avatar 2021-12-29

When using TailwindCSS, <button> has been reset by CSS Reset. We have to use utilities to compose a simple button.

Version

TailwindCSS 3.0

Simple Button

button000

Simple button with gray background and black text.

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://cdn.tailwindcss.com"></script>
  <title>TailwindCSS</title>
</head>
<body>
  <button class="text-gray-800 bg-gray-200 rounded-lg px-3 py-1">Button</button>
</body>
</html>

Line 10

<button class="text-gray-800 bg-gray-200 rounded-lg px-3 py-1">Button</button>

<button> with basic style :

  • text-gray-800 : set foreground text color
  • bg-gray-200 : set background color
  • rounded-lg : set rounded corner
  • px-3 : set horizontal padding
  • py-1 : set vertical padding

Conclusion

  • We can use other utilities to style <button>