⇧
vadnica-logo
Editor My Blog Password Manager Finance My Services About the Project Telegram O meni O meni

CSS Buttons

Buttons are designed to trigger actions and are most commonly used in conjunction with JavaScript. Therefore, in this CSS tutorial, we will learn how to style buttons, including their background and text colors. The examples demonstrate how to set button colors, borders, and more. Button sizes adapt to the font, so we do not need to set sizes manually unless we want them to vary. Buttons on a website can significantly improve the user experience.

EXAMPLE
RESULT
Property Example Description
Basic Styling
background-colorbackground-color: #4CAF50; Sets the button background color
colorcolor: white; Sets the button text color
paddingpadding: 12px 24px; Sets internal spacing (button size)
borderborder: none; Removes or sets the button border
border-radiusborder-radius: 8px; Rounded corners of the button
cursorcursor: pointer; Shows hand cursor on hover (clickable)
font-sizefont-size: 16px; Sets the button font size
font-weightfont-weight: 600; Sets the font weight
Purpose-Based Buttons
.primarybackground-color: #4CAF50; color: white; Primary action (e.g., "Submit", "Save")
.secondarybackground-color: white; border: 2px solid #4CAF50; Secondary action (outlined button)
.warningbackground-color: #ff9800; color: white; Warning action (e.g., "Delete", "Caution")
.neutralbackground-color: #f5f5f5; color: black; Neutral action (e.g., "Cancel")
Sizes
.smallpadding: 8px 16px; font-size: 14px; Small button
.mediumpadding: 12px 24px; font-size: 16px; Medium button (default)
.largepadding: 16px 32px; font-size: 18px; Large button
Shadows
box-shadowbox-shadow: 0 4px 6px rgba(0,0,0,0.1); Soft shadow below the button
box-shadow (multi)box-shadow: 0 2px 4px ..., 0 4px 8px ...; Multi-layer shadow for depth
box-shadow: insetbox-shadow: inset 0 2px 4px rgba(0,0,0,0.2); Inner shadow (pressed effect)
Shapes
.circlewidth: 100px; height: 100px; border-radius: 50%; Fully circular button
.pillborder-radius: 50px; Pill shape (very rounded edges)
.asymmetricborder-radius: 20px 5px; Asymmetrically rounded corners
States and Effects
:hoverbackground-color: #45a049; transform: translateY(-2px); Change on mouse hover
:activetransform: translateY(1px); Change on click (pressed effect)
:disabledopacity: 0.6; cursor: not-allowed; Disabled button (not clickable)
transitiontransition: all 0.3s ease; Smooth transition between states