CSS Button Generator

What is the CSS button generator?

The CSS button generator is a free online tool to design a button and copy its HTML and CSS code, ready to paste into your website.

Choose the text, the font, the colors or a gradient, the border, the rounded corners and the shadow, and see the real button change as you go. The code also includes the hover, pressed and focus states, with a smooth transition between them.

Need an image instead? The Button Generator makes the same button as a PNG, with its hover and pressed states as separate images or a sprite sheet, for games and apps.

How to create a CSS button?

  1. Click one of the styles below to start from it, or start from the default button.
  2. Type the button text and choose its font, size and color.
  3. Change the button options: background color or gradient, padding or a fixed size, rounded corners, border and shadow.
  4. Adjust the hover and pressed states, and check them by moving the mouse over the preview and clicking it, or with the "preview state" buttons.
  5. Click "Copy HTML" and "Copy CSS" and paste the code into your page and your stylesheet, or "Download HTML file" to get a page with the button.

Button styles

Click a style to apply it to your button. The styles are shown with your own text and font, and keep them when applied.

Flat
Pill
Outline
Soft shadow
Gradient
3D push
Glass
Brutalist
Dark
Embossed
Danger
Neon

Classic styles

The examples of the Button Generator, in CSS. The emboss and the text outline are approximations of the image versions.

Classic gradient
Horizontal gradient
Radial glow
Sharp shadow
Classic flat
Candy
Glossy pill
Web 2.0
Metal
Glass
Flat pill
Rounded flat
Outline
Diagonal gradient
Multi-color gradient
Gradient pill
Gradient bar
Pastel
3D push
Neumorphism
Letterpress
Neon
Dark
Retro desktop
Brutalist

Button options

Text
Text outline
Text shadow
Button
Blurs what is behind a see-through button (glass).
Gloss
Button border
Shadow
Emboss
Hover and pressed states
Positive values make the button lighter, negative values darker.
Optional: a color that replaces the background on hover.
How far the button rises on hover.
How far the pressed button moves toward its shadow (or down, without a shadow).
How long the change between states takes. 0 changes at once.
Focus
Shown when the button is reached with the keyboard (Tab).
Code
rem sizes follow the font size of the page (1rem = 16px by default).

Generated button

Or hover and click the button below.
HTML
<button class="btn" type="button">Button</button>
CSS
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 12px 24px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  color: #ffffff;
  background: #2563eb;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.btn:hover {
  background: #2159d4;
}

.btn:active {
  background: #1e4fbc;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

Need it as an image? Open this button in the Button Generator to download it as a PNG, with its hover and pressed states.

How to use the code

  1. Paste the CSS into your stylesheet, or between <style> and </style> in the <head> of your page.
  2. Paste the HTML where the button goes. The text can be changed in the HTML, and the button grows with it when its size is "fit to text".
  3. To make it do something, add an onclick or a script, or put it in a form. For a button that opens another page, choose "<a> (link)" in the "HTML element" option and change the href.
  4. Every button with the class gets the style, so you can use it for many buttons. Change the class name if your site already uses btn.

The "Copy as one page" and "Download HTML file" buttons give a complete HTML page with the button, to open in a browser or to start a new page from.

Button options

Every color field accepts any CSS color: a hexadecimal code like #1e90ff, a name like white or orange, rgb(), rgba(), hsl() or transparent. You can also pick a color with the color picker: click the square next to the field to open it.

Text

FieldDescriptionCSS
textThe button text. Press ENTER to start a new line.a <br> in the HTML
text colorThe color of the text.color
text sizeThe size of the text, in pixels.font-size
fontThe font of the text. Each choice is a list of similar fonts, so the text looks close on computers without the first one. Choose "Custom font family" to type any font family, like a web font your page loads.font-family
bold, italicBold or italic text.font-weight, font-style
line heightThe height of each line of text, as a multiple of the text size. It changes the height of the button too.line-height

Text outline

FieldDescriptionCSS
text outlineIf this option is checked, the text has an outline.
text outline sizeHow far the outline goes outside the letters, in pixels.
text outline colorThe color of the outline.
outline method"Text stroke" draws a smooth outline around the letters, behind them, so the letters keep their shape. "Text shadows" makes the outline from 16 copies of the text around it, which also works in old browsers but looks less smooth on large outlines.-webkit-text-stroke with paint-order, or text-shadow

Text shadow

FieldDescriptionCSS
text shadowIf this option is checked, the text has its own shadow, apart from the shadow of the button. With the text color, no offset and a blur, it makes the glow of neon letters. With a light color, an offset y of 1 and no blur, it makes the letters look pressed into the button (letterpress).text-shadow
text shadow blurHow blurred the text shadow is, in pixels. 0 makes a sharp copy of the letters.
text shadow color and opacityThe color of the text shadow, and how opaque it is, from 0% to 100%.
text shadow offset x and yHow far the text shadow is moved from the letters, in pixels. 0 and 0 make a glow all around them.

Button

FieldDescriptionCSS
background"Solid color", "horizontal gradient" (left to right), "vertical gradient" (top to bottom) or "radial gradient" (from the center to the edges).background, linear-gradient(), radial-gradient()
button colorThe color of the button. Only shown for "solid color". Use transparent for a button with only a border, or an rgba() color for a see-through button.background
top and bottom colorsThe colors of a vertical gradient.linear-gradient(to bottom, ...)
left and right colorsThe colors of a horizontal gradient.linear-gradient(to right, ...)
angle, start and end colorsThe "linear gradient (angle)" style goes from the start color to the end color in the direction of the angle, in degrees: 0 goes up, 90 to the right, 180 down, and 135 to the bottom right (a diagonal gradient). The corners get exactly the start and end colors.linear-gradient(135deg, ...)
center and edge colorsThe colors of a radial gradient. It is an ellipse with the proportions of the button, which reaches the corners.radial-gradient(...)
middle colorA third color between the two colors of a gradient, at the middle color position (50% is halfway). A position close to one end makes that color a thin band; the same color at both ends and a lighter middle gives a shiny band across the button.a color stop, like #8b5cf6 50%
pill shapeFully round ends at any size, whatever the height of the button. The border radius is then not used.border-radius: 9999px
size"Fit to text" makes the button as large as the text plus the padding, so it grows with the text. "Fixed size" gives every button the same width and height, with the text centered.padding, or width and height
horizontal and vertical paddingThe space between the text and the edges of the button, in pixels. Only for "fit to text".padding
button width and heightThe size of the button in pixels, including the border. Only for "fixed size".width, height
border radiusThe radius of the corners, in pixels. 0 makes square corners. Hidden when the pill shape is on.border-radius
background blurBlurs what is behind the button, in pixels. Only visible when the button color is see-through, like rgba(255, 255, 255, 0.2): it makes the frosted glass look.backdrop-filter

Gloss

FieldDescriptionCSS
glossAdds white light on the top of the button, under the text, for a shiny look. It stays the same on hover and when pressed.
gloss style"Highlight" is a round shape inside the button, a few pixels from its edges, like candy and "aqua" buttons; on a pill button it is a pill too. "Band" covers the whole top of the button and ends with a sharp edge, like the glossy buttons of the "Web 2.0" years.a ::before element (highlight) or a background layer (band)
gloss opacityHow bright the gloss is at its top, in percent. It fades to a fifth of that at its bottom.linear-gradient
gloss sizeHow far down the gloss goes, in percent of the button height. 50% covers the top half.height, or the gradient stops
gloss insetThe space between the highlight and the top and sides of the button, in pixels. Only for the highlight.top, left, right

Button border

FieldDescriptionCSS
button borderIf this option is checked, the button has a border.border
border sizeThe width of the border, in pixels.border
border colorThe color of the border.border

Shadow

FieldDescriptionCSS
shadowIf this option is checked, the button has a drop shadow.box-shadow
shadow blurHow blurred the shadow is, in pixels. 0 makes a hard shadow with sharp edges.box-shadow
shadow colorThe color of the shadow. A shadow in the color of the button makes it look like it glows.box-shadow
shadow opacityHow opaque the shadow is, from 0% (invisible) to 100% (solid). Soft shadows are usually between 15% and 40%.box-shadow with an rgba() color
shadow offset x and yHow far the shadow is moved to the right and down, in pixels. Negative values move it to the left and up.box-shadow
second shadowA second shadow, drawn behind the first one, with its own blur, color, opacity and offsets. A light shadow toward the top left with a dark one toward the bottom right makes neumorphism (soft UI), and a soft shadow under the hard shadow of a 3D button makes it look lifted.a second box-shadow in the list

Emboss

FieldDescriptionCSS
embossIf this option is checked, the top left edges of the button are lighter and the bottom right edges darker, so it looks raised.two inset box-shadows
emboss radiusHow far into the button the light and the shade go, in pixels.box-shadow
emboss intensityHow strong the light and the shade are.box-shadow

Hover and pressed states

The hover state is shown while the mouse is over the button, and the pressed state while it is clicked or touched. Both are made from the normal button, so changing the other options changes them too.

FieldDescriptionCSS
hover brightnessHow much lighter the background is on hover, in percent. Negative values make it darker, which is usual for colored buttons.:hover, background
hover button colorOptional. A background color for the hover state instead of the lighter or darker one, for example to fill a button that only has a border. Leave it empty for the automatic color.:hover, background
hover text color, hover border colorOptional. The color of the text and of the border on hover. Leave them empty to keep the normal colors.:hover, color, border-color
hover liftHow many pixels the button rises on hover.:hover, transform
pressed brightnessHow much lighter (or, with negative values, darker) the background is while pressed, starting from the hover button color if there is one.:active, background
pressed offsetHow many pixels the pressed button moves toward its shadow, while the shadow stays in place, so it looks pushed down. It never moves further than the shadow offset. Without a shadow offset, the button moves down.:active, transform, box-shadow
invert emboss when pressedThe light and the shade of the emboss swap while pressed, so the button looks pushed in. Only shown when the emboss is on.:active, box-shadow
shadows inside when pressedThe shadows move inside the button while it is pressed, with the same offsets, so the button looks pressed into the page: the pressed state of neumorphism.:active, box-shadow: inset
transitionHow long the change from one state to the other takes, in milliseconds. 0 changes at once. Gradients change at once anyway, because browsers can't fade between them.transition

Focus

FieldDescriptionCSS
focus ringA ring around the button when it is reached with the Tab key, so people who use the keyboard can see where they are. It is not shown when the button is clicked with the mouse. When it is off, the browser shows its own focus ring.:focus-visible, outline
focus ring colorThe color of the ring. Choose one that stands out on the background of your page.outline

Code

FieldDescriptionCSS
HTML element<button> for a button that does something on the page, like sending a form or opening a menu. <a> for a link that looks like a button and opens another page.
class nameThe name of the CSS class of the button. Letters, digits, - and _, starting with a letter..btn
unitspx or rem for the text size, the padding and the width and height. With rem, the button grows when the visitor makes the text of the browser larger.

Preview

FieldDescription
preview backgroundThe background behind the generated button and the styles: a checkerboard, white, light gray, dark, colorful, the color of the button or the page background. Use it to check how the button looks on your page; neumorphism only works on a page of the button color. It is not part of the code.
preview stateShows the button in one state: normal, hover, pressed or focus. You can also move the mouse over the button and click it, or reach it with the Tab key.

Frequently Asked Questions (FAQ)

Is the CSS button generator free to use?

Yes, this tool is 100% free and works directly in your browser, with no installation and no sign-up required. Nothing you type is sent to a server.

Can I use the code in a commercial project?

Yes. The code is yours: use it in any website or app, including commercial ones, without credit.

How do I add the button to my website?

Paste the CSS into your stylesheet and the HTML where the button goes, as explained in how to use the code above. Or click "Download HTML file" to get a page that already has both.

Can I make a link that looks like a button?

Yes. Choose "<a> (link)" in the "HTML element" option, and replace the # in the href of the HTML with the address of the page. The CSS is the same.

Does it work in every browser?

Yes, in all current browsers: Chrome, Edge, Firefox and Safari, on computers and phones. The text outline with "text stroke" relies on paint-order for HTML text, which some older browser versions don't support: there the outline covers part of the letters. Choose "text shadows" if you need to support them.

Why doesn't the hover of my gradient button fade?

Browsers can't animate from one gradient to another, so a gradient button changes color at once, even with a transition. Solid colors, the shadow, the border and the movement still fade. For a smooth hover on a gradient button, set the hover brightness to 0 and use the hover lift instead.

Is the button accessible?

Mostly, yes. It is a real <button> (or link) with real text, so screen readers can read it and it works with the keyboard, unlike a button image. The focus ring shows where the keyboard is. Keep enough contrast between the text and the button color, especially for light text on light colors.

Why does a style look a little different from the Button Generator?

The Button Generator draws an image, pixel by pixel. Some of its effects have no exact CSS version: here the emboss is made of two inset shadows, the text outline is a stroke, and the shadow follows the box of the button, not the outline of the text. The result is close, but not identical.

Can I get the button as an image?

Yes. Click "Open this button in the Button Generator" below the code: it opens the same button in the Button Generator, where you can download it as a PNG, or its hover and pressed states as separate images or a sprite sheet.

Does it generate Tailwind CSS?

Not yet. The CSS works on any site that uses Tailwind: paste it in your CSS file and use the class name in your HTML. Pick a class name that Tailwind doesn't use, like the default btn.

Should I use px or rem?

rem is better for accessibility: when a visitor makes the text of their browser larger, the button grows with it. px keeps the exact size you see here. With the default browser settings both look the same.

Which other tools can I use to create buttons?

The Button Generator creates button images (PNG) with emboss and outlined text, the Frutiger Aero button generator creates glossy glass buttons in the Web 2.0 style, and the Styled Text Generator creates text images with outlines, glow, 3D and bloom effects.

Related tools

Button generator

Button generator

Easily generate button images with different styles.
Frutiger Aero button generator

Frutiger Aero button generator

Generate glossy Frutiger Aero buttons, with gloss, glass rim, bubbles and shadow.
Styled Text Generator

Styled Text Generator

Generate images of text with custom fonts, gradients, double outlines, shadows, glow, 3D, emboss and bloom effects.