Skip to main content

CSS Button Groups

This page covers CSS button groups and animated buttons.


CSS Horizontal Button Group

To create a group of buttons side by side, wrap them in a container element and set display: flex; on it. Add flex-wrap: wrap; so the buttons move to a new line on small screens.

Example

A horizontal button group using flexbox. The buttons change to dodgerblue on hover.

Prompt
Create a horizontal button group using CSS flexbox. Place four green buttons side by side inside a flex container with flex-wrap enabled. On hover, the buttons should change to dodgerblue.
Output: complete HTML page

CSS Bordered Button Group

Use the border property to add borders to the buttons. To make them look like one connected group, remove the right border from all buttons except the last one using the :not(:last-child) selector.

Example

Prompt
Create a horizontal group of four bordered buttons with a 1px solid green border. Remove the right border from all buttons except the last one using the :not(:last-child) selector, so they appear as one connected group. On hover, change the background color.
Output: complete HTML page

CSS Vertical Button Group

To create a vertical button group, wrap the buttons in a container and set display: flex; with flex-direction: column;. This stacks the buttons on top of each other.

Example

Prompt
Create a vertical button group using CSS flexbox with flex-direction set to column. Display four green buttons stacked on top of each other. On hover, the buttons should change to dodgerblue.
Output: complete HTML page

CSS Animated Buttons

You can add animations and transition effects to buttons using CSS.

Arrow on hover

Add an arrow that slides in when you hover over the button.

Prompt
Create a button that shows an arrow (») sliding in from the right on hover. Use a span inside the button for the arrow, with CSS transitions for opacity and padding to animate the effect.
Output: complete HTML page

Pressed effect

Add a "pressed" effect when the button is clicked.

Prompt
Create a button with a "pressed" effect on click using CSS. The button should have a box-shadow and when clicked (:active), the shadow is removed and the button moves down slightly using transform: translateY(4px).
Output: complete HTML page

Fade in on hover

Make the button fade in when you hover over it.

Prompt
Create a button that fades in on hover. Start with the button at half opacity (0.5) and transition to full opacity (1) on hover using a CSS transition.
Output: complete HTML page

Ripple effect

Add a "ripple" effect when the button is clicked.

Prompt
Create a button with a CSS ripple effect on click. Use a ::after pseudo-element with a radial-gradient background and a CSS animation that scales up and fades out when the button is clicked.
Output: complete HTML page