CSS Advanced

CSS Buttons


Discover how to use CSS to style buttons.


Basic Button Styling

------Button MUKAVA------

Example

				
					.button {
  background-color: #04AA6D; /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}
				
			

Button Colors

------Button MUKAVA------

To alter a button’s background color, use the background-color property:

Example

				
					.button1 {background-color: #04AA6D;} /* Green */
.button2 {background-color: #008CBA;} /* Blue */
.button3 {background-color: #f44336;} /* Red */
.button4 {background-color: #e7e7e7; color: black;} /* Gray */
.button5 {background-color: #555555;} /* Black */
				
			

Button Sizes

------Button MUKAVA------

se the font-size property to change the font size of a button:

Example

				
					.button1 {font-size: 10px;}
.button2 {font-size: 12px;}
.button3 {font-size: 16px;}
.button4 {font-size: 20px;}
.button5 {font-size: 24px;}
				
			

To alter a button’s padding, use the padding property:

------Button MUKAVA------

Example

				
					.button1 {padding: 10px 24px;}
.button2 {padding: 12px 28px;}
.button3 {padding: 14px 40px;}
.button4 {padding: 32px 16px;}
.button5 {padding: 16px;}
				
			

Rounded Buttons

------Button MUKAVA------

For buttons, apply the border-radius attribute to add rounded corners:

Example

				
					.button1 {border-radius: 2px;}
.button2 {border-radius: 4px;}
.button3 {border-radius: 8px;}
.button4 {border-radius: 12px;}
.button5 {border-radius: 50%;}
				
			

Colored Button Borders

------Button MUKAVA------

To give a button a colorful border, use the border property:

Example

				
					.button1 {
  background-color: white;
  color: black;
  border: 2px solid #04AA6D; /* Green */
}
...
				
			

Hoverable Buttons

------Button MUKAVA------

When hovering the mouse over a button, you can alter its appearance by using the :hover selector.

A helpful hint is to use the transition-duration attribute to calculate the “hover” effect’s speed:

Example

				
					.button {
  transition-duration: 0.4s;
}

.button:hover {
  background-color: #04AA6D; /* Green */
  color: white;
}
...
				
			

Shadow Buttons

------Button MUKAVA------

To give a button shadow, use the box-shadow property:

Example

				
					.button1 {
  box-shadow: 0 8px 16px 0 rgba(0,0,0,0.2), 0 6px 20px 0 rgba(0,0,0,0.19);
}

.button2:hover {
  box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);
}
				
			

Disabled Buttons

------Button MUKAVA------

To add transparency to a button and give it a “disabled” appearance, use the opacity property.

Tips: You can also add the “not-allowed” cursor attribute, which will cause a “no parking sign” to appear while the mouse is over the button:

Example

				
					.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
				
			

Button Width

------Button MUKAVA------

The button’s default size (as wide as its content) is set by the text within it. To alter a button’s width, use the width property:

Example

				
					.button1 {width: 250px;}
.button2 {width: 50%;}
.button3 {width: 100%;}
				
			

Button Groups

------Button MUKAVA------

To build a button group, remove the margins from each button and add float:left to it.

Example

				
					.button {
  float: left;
}
				
			

Bordered Button Group

------Button MUKAVA------

To make a button group with borders, use the border property:

Example

				
					.button {
  float: left;
  border: 1px solid green;
}
				
			

Vertical Button Group

------Button MUKAVA------

Change the float:left to display:block to arrange the buttons below one another rather than side by side:

Example

				
					.button {
  display: block;
}
				
			

Button on Image

------Button MUKAVA------

Animated Buttons

Example

Add an arrow on hover:

------Button MUKAVA------

Example

Add a “pressed” effect on click:

------Button MUKAVA------

Example

Fade in on hover:

------Button MUKAVA------

Example

Add a “ripple” effect on click:

------Button MUKAVA------

Share this Doc

CSS Buttons

Or copy link

Explore Topic