Buttons


Buttons

Buttons are one of the most used elements in HTML. With the help of CSS, buttons can be styled in various ways. Multiple properties can be used on a button element. We can provide border, colour, padding, and so much more to the button using CSS.

Button Colors

background-color is used to change the colour of the button.
The default colour of the button is white.

Button Sizes

font-size is used to change the size of the button.

E.g., .button_name { font-size: 25px;}

padding is used to define the length and breadth of the button.

E.g., .button_name { padding: 25px 40px ;}

Rounded Button

We can use some border-radius attribute to give the shape to the button.
E.g., button_name { border-radius: 2px;}
button_name { border-radius: 50 %;}

Coloured Button Borders

By using border we can colour button border.
E.g., button_name { border: 2px solid Blue;}

Hover Button

Hover is used to styling the button in such a way so that when the mouse is over the button, then it will show effect.
Use the transition-duration attribute for the time of the hover effect.
E.g., button_name { transition-duration: 0.5s;}
button_name:hover {******}

The style we can provide to the button:-

  • text-align:
  • text-decoration
  • display: //inline-block
  • margin
  • cursor //pointer, not-allowed (By doing this, the button will become disable)
  • box-shadow
  • width
  • float
  • image button
  • Vertical and horizontal buttons

These properties are showcased in the examples below:-

Example No.1:

<html> <html lang="en-US"> <style> .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; } </style> </head> <body> <h2>Knowledge2life</h2> <button>Knowledge2life button</button> </body> </html>

OUTPUT:

Knowledge2life

Example No.2:

<html> <html lang="en-US"> <style> .button { background-color: #4CAF50; color: white; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; } </style> </head> <body> <h2>Knowledge2life</h2> <a href="#" class="button">Link Knowledge2life</a> <button class="button">Knowledge2life 1</button> <input type="button" class="button" value="Website Knowledge2life input"> </body> </html>

OUTPUT:

Knowledge2life