Ask coding questions

← Back to all posts
how to add button in html ?
RamBarabdeCoder (1)

plz tell how to add it and then plz give codes and also any new thing you about buttons like color changing and many things in html language.


I can help you! The way to create a button is like this:

<button href="(location where u want the user to go after clicking on it)">Name of the button</button>

To change the color, you can do:

<button id="button-red">This is a button that is red</button>

and in the CSS file u do:

#button-red {
    background-color: red;

and boom ur done


If my comment answered the question then select the green check mark next to it, thanks!

RamBarabdeCoder (1)

Thank you all @Aphmeta ,@InvisibleOne,@ruiwenge2 and more

InvisibleOne (3226)

In the HTML file

<button onclick="alert('You clicked me!');">Click Me!</button>

then in the css

button {
  padding: 15px;
  font-size: 10px;
  color: white;
  font-family: 'Trebuchet MS';
  background-color: darkgrey;
  border-radius: 5px;
  border: 6px solid black;

Something like that

RamBarabdeCoder (1)

Can Any one tell me that when the cursor will goto the button then how it will change color

ruiwenge2 (1209)

@RamBarabdeCoder in css:

button:hover {
background: blue;
ruiwenge2 (1209)

@ruiwenge2 u forgot about href and he also asked for color code


@ruiwenge2 and u need to specify the language as html when u put code markdown like

<button href="">YouTube</button>