Styling Buttons with CSS

CSS can transform plain HTML buttons into attractive, interactive elements with colors, borders, shadows, and hover effects.

Button Styling

Remove default styles with border: none and background.

Add padding, border-radius, and colors for visual appeal.

Use :hover, :active, and :focus for interactivity.

cursor: pointer improves user experience.

Transitions create smooth state changes.

/* Basic button */
.button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 12px 24px;
  text-align: center;
  font-size: 16px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.button:hover {
  background-color: #45a049;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.button:active {
  transform: translateY(0);
}

/* Outline button */
.button-outline {
  background-color: transparent;
  border: 2px solid #4CAF50;
  color: #4CAF50;
}