CSS Buttons

CSS Tutorial


Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

CSS Advanced


Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2298

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2302

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2308

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2312

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2316

Warning: Attempt to read property "post_status" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2320

Warning: Attempt to read property "ID" on null in /home/mydevhel/public_html/wp-admin/includes/template.php on line 2334

CSS Responsive

CSS Grid

CSS Buttons

Basic Button Styling

HTML
				
					<button>Default Button</button>
<a href="#" class="button">Link Button</a>
<button class="button">Button</button>
<input type="button" class="button" value="Input Button">
				
			
CSS
				
					.button {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}
				
			

Output

css buttons

Rounded Buttons

Use the border-radius property to add rounded corners to a button:

HTML
				
					<h2>Rounded Buttons</h2>
<p>Add rounded corners to a button with the border-radius property:</p>
<button class="button button1">2px</button>
<button class="button button2">4px</button>
<button class="button button3">8px</button>
<button class="button button4">12px</button>
<button class="button button5">50%</button
				
			
CSS
				
					.button {
  background-color: #03989E;
  border: none;
  color: white;
  padding: 20px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

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

Output

rounded buttons

Button Sizes

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

HTML

				
					<button class="button button1">10px</button>
<button class="button button2">12px</button>
<button class="button button3">16px</button>
<button class="button button4">20px</button>
<button class="button button5">24px</button>
				
			
CSS
				
					.button {
  background-color: #03989E; 
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  margin: 4px 2px;
  cursor: pointer;
}

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

Output

button sizes

The padding property  is used to change the padding of a button:

HTML
				
					<h2>Button Padding</h2>
<p>Change the padding of button with the padding property:</p>
<button class="button button1">10px 24px</button>
<button class="button button2">12px 28px</button>
<button class="button button3">14px 40px</button>
<button class="button button4">32px 16px</button>
<button class="button button5">16px</button>
				
			
CSS
				
					.button {
  background-color: #03989E; 
  border: none;
  color: white;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

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

Output

button padding

Colored Button Borders

The border property is used to add a colored border to a button:

HTML
				
					<h2>Colored Button Borders</h2>
<p>Use the border property to add a border to the button:</p>
<button class="button button1">Green</button>
<button class="button button2">Blue</button>
<button class="button button3">Red</button>
<button class="button button4">Gray</button>
<button class="button button5">Black</button>
				
			
CSS
				
					.button {
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.button1 {
  background-color: white; 
  color: black; 
  border: 2px solid #4CAF50;
}

.button2 {
  background-color: white; 
  color: black; 
  border: 2px solid #008CBA;
}

.button3 {
  background-color: white; 
  color: black; 
  border: 2px solid #f44336;
}

.button4 {
  background-color: white;
  color: black;
  border: 2px solid #e7e7e7;
}

.button5 {
  background-color: white;
  color: black;
  border: 2px solid #555555;
}
				
			

Output

colored button border

Hoverable Buttons

The :hover selector is used to change the style of a button when you move the mouse over it.

HTML
				
					<h2>Hoverable Buttons</h2>

<button class="button button1">Green</button>
<button class="button button2">Blue</button>
<button class="button button3">Red</button>
<button class="button button4">Gray</button>
<button class="button button5">Black</button>
				
			
CSS
				
					.button {
  background-color: #4CAF50; /* Green */
  border: none;
  color: white;
  padding: 16px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  transition-duration: 0.4s;
  cursor: pointer;
}

.button1 {
  background-color: white; 
  color: black; 
  border: 2px solid #03989E;
}

.button1:hover {
  background-color: #03989E;
  color: white;
}

.button2 {
  background-color: white; 
  color: black; 
  border: 2px solid #008CBA;
}

.button2:hover {
  background-color: #008CBA;
  color: white;
}

.button3 {
  background-color: white; 
  color: black; 
  border: 2px solid #f44336;
}

.button3:hover {
  background-color: #f44336;
  color: white;
}

.button4 {
  background-color: white;
  color: black;
  border: 2px solid #e7e7e7;
}

.button4:hover {background-color: #e7e7e7;}

.button5 {
  background-color: white;
  color: black;
  border: 2px solid #555555;
}

.button5:hover {
  background-color: #555555;
  color: white;
}
				
			

Output

Hoverable Buttons

Shadow Buttons

The box-shadow property is used to add shadows to a button:

HTML
				
					<h2>Shadow Buttons</h2>
<p>Use the box-shadow property to add shadows to the button:</p>
<button class="button button1">Shadow Button</button>
<button class="button button2">Shadow on Hover</button>
				
			
CSS
				
					.button {
  background-color: #03989E;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
  -webkit-transition-duration: 0.4s; /* Safari */
  transition-duration: 0.4s;
}

.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);
}
				
			

Output

shadow button

Disabled Buttons

The opacity property is used to add transparency to a button (creates a “disabled” look.

HTML
				
					<h2>Disabled Button</h2>
<button class="button">Normal Button</button>
<button class="button disabled">Disabled Button</button>
				
			
CSS
				
					.button {
  background-color: #03989E;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

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

Output

Button Width

The size of the button is used is determined by its text content (as wide as its content). Using the width property to change the width of a button:

HTML
				
					<h2>Set Button Widths</h2>
<button class="button button1">250px</button><br>
<button class="button button2">50%</button><br>
<button class="button button3">100%</button>
				
			
CSS
				
					.button {
  background-color:#03989E;
  border: none;
  color: white;
  padding: 15px 32px;
  text-aliinggn: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

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

Output

set buttons width

Vertical Button Group

Using the display:block instead of float:left to group the buttons below each other, instead of side by side:

HTML
				
					<h2>Bordered Button Group</h2>
<div class="btn-group">
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
</div>
				
			
CSS
				
					.btn-group .button {
  background-color: #03989E;
  border: 1px solid green;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  cursor: pointer;
  float: left;
}

.btn-group .button:not(:last-child) {
  border-right: none; /* Prevent double borders */
}

.btn-group .button:hover {
  background-color: #3e8e41;
}
				
			

Output

bordered button group

Bordered Button Group

The border property is use to create a bordered button group:

HTML
				
					<h2>Vertical Button Group</h2>
<div class="btn-group">
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
  <button class="button">Button</button>
</div>
				
			
CSS
				
					.btn-group .button {
  background-color: #03989E;
  border: 1px solid green;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
  width: 150px;
  display: block;
}

.btn-group .button:not(:last-child) {
  border-bottom: none; /* Prevent double borders */
}

.btn-group .button:hover {
  background-color: #3e8e41;
}
				
			

Output

verticle button group