
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.
Click a style to apply it to your button. The styles are shown with your own text and font, and keep them when applied.
The examples of the Button Generator, in CSS. The emboss and the text outline are approximations of the image versions.
<button class="btn" type="button">Button</button>
.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.
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.
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.
| Field | Description | CSS |
|---|---|---|
| text | The button text. Press ENTER to start a new line. | a <br> in the HTML |
| text color | The color of the text. | color |
| text size | The size of the text, in pixels. | font-size |
| font | The 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, italic | Bold or italic text. | font-weight, font-style |
| line height | The height of each line of text, as a multiple of the text size. It changes the height of the button too. | line-height |
| Field | Description | CSS |
|---|---|---|
| text outline | If this option is checked, the text has an outline. | |
| text outline size | How far the outline goes outside the letters, in pixels. | |
| text outline color | The 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 |
| Field | Description | CSS |
|---|---|---|
| text shadow | If 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 blur | How blurred the text shadow is, in pixels. 0 makes a sharp copy of the letters. | |
| text shadow color and opacity | The color of the text shadow, and how opaque it is, from 0% to 100%. | |
| text shadow offset x and y | How far the text shadow is moved from the letters, in pixels. 0 and 0 make a glow all around them. |
| Field | Description | CSS |
|---|---|---|
| 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 color | The 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 colors | The colors of a vertical gradient. | linear-gradient(to bottom, ...) |
| left and right colors | The colors of a horizontal gradient. | linear-gradient(to right, ...) |
| angle, start and end colors | The "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 colors | The colors of a radial gradient. It is an ellipse with the proportions of the button, which reaches the corners. | radial-gradient(...) |
| middle color | A 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 shape | Fully 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 padding | The space between the text and the edges of the button, in pixels. Only for "fit to text". | padding |
| button width and height | The size of the button in pixels, including the border. Only for "fixed size". | width, height |
| border radius | The radius of the corners, in pixels. 0 makes square corners. Hidden when the pill shape is on. | border-radius |
| background blur | Blurs 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 |
| Field | Description | CSS |
|---|---|---|
| gloss | Adds 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 opacity | How bright the gloss is at its top, in percent. It fades to a fifth of that at its bottom. | linear-gradient |
| gloss size | How far down the gloss goes, in percent of the button height. 50% covers the top half. | height, or the gradient stops |
| gloss inset | The space between the highlight and the top and sides of the button, in pixels. Only for the highlight. | top, left, right |
| Field | Description | CSS |
|---|---|---|
| button border | If this option is checked, the button has a border. | border |
| border size | The width of the border, in pixels. | border |
| border color | The color of the border. | border |
| Field | Description | CSS |
|---|---|---|
| shadow | If this option is checked, the button has a drop shadow. | box-shadow |
| shadow blur | How blurred the shadow is, in pixels. 0 makes a hard shadow with sharp edges. | box-shadow |
| shadow color | The color of the shadow. A shadow in the color of the button makes it look like it glows. | box-shadow |
| shadow opacity | How 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 y | How far the shadow is moved to the right and down, in pixels. Negative values move it to the left and up. | box-shadow |
| second shadow | A 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 |
| Field | Description | CSS |
|---|---|---|
| emboss | If 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 radius | How far into the button the light and the shade go, in pixels. | box-shadow |
| emboss intensity | How strong the light and the shade are. | box-shadow |
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.
| Field | Description | CSS |
|---|---|---|
| hover brightness | How much lighter the background is on hover, in percent. Negative values make it darker, which is usual for colored buttons. | :hover, background |
| hover button color | Optional. 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 color | Optional. The color of the text and of the border on hover. Leave them empty to keep the normal colors. | :hover, color, border-color |
| hover lift | How many pixels the button rises on hover. | :hover, transform |
| pressed brightness | How 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 offset | How 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 pressed | The 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 pressed | The 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 |
| transition | How 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 |
| Field | Description | CSS |
|---|---|---|
| focus ring | A 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 color | The color of the ring. Choose one that stands out on the background of your page. | outline |
| Field | Description | CSS |
|---|---|---|
| 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 name | The name of the CSS class of the button. Letters, digits, - and _, starting with a letter. | .btn |
| units | px 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. |
| Field | Description |
|---|---|
| preview background | The 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 state | Shows 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. |
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.


