CSS Buttons

❮ Previous Home Next ❯

In this chapter you will learn how to customize buttons.




Basic Buttons

The following example show how to style buttons:



Example

.button {
  background-color: #0069FF;
  border: none;
  outline: none;
  color: white;
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
}

Button Colors

By using background-color CSS property you can change Background color of the buttons.



Example

.button1 {background-color: red;}
.button2 {background-color: green;}
.button3 {background-color: blue;}
.button4 {background-color: gray;}
.button5 {background-color: black;}



Button Sizes

By using font-size CSS property you can change size of the buttons.



Example

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

By using padding CSS property you can also change size of the buttons.

Example

.button1 {padding: 8px;}
.button2 {padding: 12px;}
.button3 {padding: 16px;}
.button4 {padding: 24px;}
.button5 {padding: 32px;}



Rounded Buttons

By using border-radius CSS property you can change make buttons rounded.

Example

.button1 {border-radius: 4px;}
.button2 {border-radius: 8px;}
.button3 {border-radius: 16px;}
.button4 {border-radius: 24px;}
.button5 {border-radius: 32px;}



Buttons Border Color

By using border CSS property you can change color of the buttons border.



Example

.button1 {border: 2px solid red;}
.button2 {border: 2px solid green;}
.button3 {border: 2px solid blue;}
.button4 {border: 2px solid gray;}
.button5 {border: 2px solid black;}






Hoverable Buttons

By using :hover selector and transition-duration CSS property you can make smooth hoverable effect on buttons.

You can make your own button by just changing background-color and border color.

Example

.button1 {
  background-color: #0069FF;
  border: 2px solid #0069FF;
  outline: none;
  color: white;
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  display: inline-block;
  margin: 8px;
  font-size: 16px;
  transition-duration: 0.5s;
}

.button1:hover{
  background: white;
  color: black;
}

.button2 {
  background-color: white;
  border: 2px solid #0069FF;
  outline: none;
  color: black;
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  display: inline-block;
  margin: 8px;
  font-size: 16px;
  transition-duration: 0.5s;
}

.button2:hover{
  background: #0069FF;
  color: black;
}



Box Shadow Buttons

By using box-shadow CSS property you can make button shadow and after hover shadow.

Example

button {
  background-color: #0069FF;
  border: none;
  outline: none;
  color: white;
  padding: 8px 16px;
  border-radius: 4px;
  text-decoration: none;
  display: inline-block;
  margin: 8px;
  font-size: 16px;
  transition-duration: 0.5s;
}

.button1 {
  box-shadow: 0 8px 24px 0 rgba(0,0,0,0.2), 0 8px 24px 0 rgba(0,0,0,0.2);
}

.button2:hover {
  box-shadow: 0 8px 24px 0 rgba(0,0,0,0.2), 0 8px 24px 0 rgba(0,0,0,0.2);
}



Create Disabled Buttons

By using opacity CSS property you can make look like button disabled.

Example

.disabled {
  opacity: 0.5;
  cursor: none;
}



Buttons Width

To set width use CSS width property.

Example

.btn1 {
  width: 100px;
}

.btn2 {
  width: 100%;
}

.btn3 {
  width: 50%;
}



Centered Button on Image

flowers

Example

.container {
  position: relative;
  width: 100%;
  max-width: 400px;
}

.container img {
  width: 100%;
  height: auto;
}

.container button {
  position: absolute;
  top: 50%;
  left: 50%;
  margin:auto auto;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background-color: white;
  color: black;
  font-size: 16px;
  padding: 8px 16px;
  border: 0;
  cursor: pointer;
  border-radius: 5px;
  text-align: center;
}

.container button:hover {
  background-color: black;
  color: white;
}



❮ Previous Home Next ❯