Skip to main content

CSS Styling Buttons

HTML buttons can take many different looks once CSS is applied.

These properties do most of the work:

  • background-color — fills the button with a background color
  • color — colors the button's text
  • border — draws the line around the button
  • padding — controls the gap between the text and the border
  • border-radius — rounds off the button's corners
  • box-shadow — gives the button a shadow
  • text-align — puts the button's text in the center
  • font-size — controls how large the button's text appears
  • text-decoration — takes away the underline when an <a> element acts as a button
  • cursor — swaps the mouse cursor while it hovers on the button

Three elements typically serve as buttons: <button>, <input type="button">, and an <a> with button styling.


CSS Basic Button Styling

Any HTML element can pass for a button once it has a few CSS properties: a background color, some padding, a text color, and no default border.

Example

Basic button styling, shown on different HTML elements:

Prompt
Create a page showing a default unstyled button and a CSS-styled button side by side. The styled button should have a red background, white text, no border, 15px 32px padding, centered text, no text decoration, inline-block display, 16px font size, and a pointer cursor. Use a element for the default and an element for the styled one.
Output: complete HTML page

CSS Button Colors

Two properties handle color here: background-color for what sits behind the text, and color for the text itself.

Example

Each button here has its own background color:

Prompt
Create a page with five buttons in a row, each with a different background color: green (#04AA6D), blue (#008CBA), red (#f44336), gray (#e7e7e7 with black text), and black (#555555). All buttons share a base style with white text, no border, 15px 32px padding, centered text, 16px font size, and pointer cursor.
Output: complete HTML page

CSS Button Sizes

Size comes from two properties. font-size scales the text on the button, and padding adjusts how much room lies between that text and the border.

Font size buttons

The font size changes from one button to the next:

Prompt
Create a page with five buttons showing different font sizes: 10px, 12px, 16px, 20px, and 24px. All buttons share a base style with green (#04AA6D) background, white text, no border, 15px 32px padding, centered text, and pointer cursor.
Output: complete HTML page

Padding buttons

Here the padding value is what differs:

Prompt
Create a page with five buttons showing different padding values: 10px 24px, 12px 28px, 14px 40px, 32px 16px, and 16px. All buttons share a base style with green (#04AA6D) background, white text, no border, centered text, 16px font size, and pointer cursor.
Output: complete HTML page

CSS Rounded Buttons

Use border-radius to round a button's corners.

Example

Corners rounded by varying amounts:

Prompt
Create a page with five buttons showing different border-radius values: 2px, 4px, 8px, 12px, and 50%. All buttons share a base style with green (#04AA6D) background, white text, no border, 15px 32px padding, centered text, 16px font size, and pointer cursor.
Output: complete HTML page

CSS Button Borders

A button's border comes from the border property.

Example

The border style changes from one button to the next:

Prompt
Create a page with five buttons showing different border styles: 2px solid green (#04AA6D), 2px dotted blue (#008CBA), 2px dashed red (#f44336), 1px solid gray (#e7e7e7), and 1px solid dark gray (#555555). All buttons share a base style with white background, colored text matching their border, 15px 32px padding, centered text, 16px font size, and pointer cursor.
Output: complete HTML page