A square CSS button is made by giving the button equal width and height, centering its content, and setting border-radius: 0 when sharp corners are required.

Those are separate design decisions: “square” can describe the outer footprint, the corners, or both. A fixed square works well for an icon action but can crowd a longer label. Define the geometry first, use a visual tool for the visual properties, and then add the sizing and interaction rules that the tool does not supply.

how to make square button css
How to Make Square Button CSS: Sharp Corners or Sides

Separate square dimensions from square corners

Start by deciding which constraint matters. A button can have four sharp corners while remaining wider than it is tall, or it can have equal sides with rounded corners. For background and border behavior, see MDN’s CSS backgrounds and borders guide; the W3C CSS Backgrounds and Borders Level 3 specification defines how border-radius is applied.

Meaning CSS approach Practical result
Square outer footprint Set equal width and height, or use aspect-ratio: 1. The visible box is equally wide and tall when layout constraints allow.
Square corners Set border-radius: 0. The corners are sharp, but the button can still be rectangular.
Fluid square Combine a container-based width with aspect-ratio: 1. The button follows its container while retaining a preferred square ratio.
Square icon button Use equal dimensions, center the icon, and provide an accessible name. This suits a short, stable action better than a long text label.

Use box-sizing: border-box on the button so its declared width and height include padding and border. Without that rule, the default content-box model makes the final outer footprint less direct to predict. Also remember that aspect-ratio: 1 expresses a preferred ratio; flex or grid constraints and long content can still force a different result.

Build a square button from markup to stylesheet

  1. Start with a native <button> for an action and set type="button" unless form submission is intentional. Use visible text as the accessible name, or give an icon-only control an aria-label. For navigation, use an <a> with an href and apply the same class.

    <button class="square-button" type="button" aria-label="Open settings">&#9881;&lt;/button>

  2. In the CSS Button Generator, choose background, text, and border colors as six-digit hexadecimal values. Adjust border width, corner radius, horizontal and vertical padding, font size and weight, and the simple drop shadow. Set the radius to zero for sharp corners. For an icon square, use little or no padding; for a text button, retain enough room around the label.

    The generator applies those values to a real HTML button preview and produces ordinary CSS without requiring an external library.

  3. Inspect the real preview at desktop and mobile widths. Check the label, spacing, border, typography, and shadow at both sizes. The preview cannot prove that the outer footprint is square because the generator has no width or height control, so treat it as the styling baseline rather than the final geometry test.

  4. Copy the complete .button rule, rename it to something specific such as .square-button, and scope it if necessary. The generic selector can collide with another stylesheet. The base output covers background-color, color, border, border-radius, padding, font-size, font-weight, box-shadow, and cursor.

  5. Add the square geometry in your stylesheet. For a fixed square, give width and height the same value. For a preferred square ratio, set aspect-ratio: 1 and let one dimension remain automatic. Center the content with inline-flex alignment. The following is one complete starting point:

    .square-button { background-color: #2563eb; color: #ffffff; border: 1px solid #1d4ed8; border-radius: 0; padding: 0; font-size: 1rem; font-weight: 600; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); cursor: pointer; box-sizing: border-box; width: 3rem; height: 3rem; display: inline-flex; align-items: center; justify-content: center; }

    Treat this size as a starting value rather than a universal touch-target guarantee. Replace it with an existing project token when possible, and keep minimum touch dimensions in mind.

  6. Add interactive rules after copying the base class. Hover, active, focus-visible, and disabled behavior depends on what the button does, so the generator intentionally leaves those states out. Do not remove a visible focus indicator unless an equally clear replacement is present.

  7. Test the completed button with short and long labels, translated text, icons, narrow screens, zoom, keyboard navigation, and touch. Check contrast in the default, hover, active, disabled, and focus states with a dedicated contrast tool, and verify the focus indicator under forced colors.

Choose a sizing strategy that survives real labels

A fixed square is predictable for an icon, but text can overflow or force the box to grow. A fluid square can use a width tied to its container and aspect-ratio: 1, yet long words may still create overflow because the ratio is a preference rather than a promise. Choose the model that matches the label instead of hiding content merely to preserve a shape.

  • Fixed square: Best for a stable icon action; add an accessible name and test the control at different zoom levels.
  • Fixed square with a short label: Workable when the longest supported label has enough room and cannot expand the control.
  • Long or translated label: Let the width follow the content, increase both dimensions, or use a rectangular button.

For a wider responsive comparison, including how width and wrapping behave inside different containers, see how to make a CSS button responsive at every width. A square control should also be checked beside rectangular controls so the component set remains visually consistent.

Add interaction and keyboard states

The copied base class describes appearance, while interaction states provide feedback for different conditions. Add these rules in your own stylesheet rather than expecting the generator to supply them.

State Useful change Requirement
:hover Change the background slightly or adjust the border. Keep the text contrast readable in the changed state.
:active Reduce the shadow or move the button slightly with a transform. Do not shift surrounding layout or obscure the label.
:focus-visible Add a clear outline with an offset. Do not remove the outline without an equally visible replacement.
:disabled Add the disabled attribute and change the cursor and styling. Signal unavailability with more than reduced opacity.

Loading behavior also depends on the product rather than the base style. Use existing color and spacing tokens where possible, and check each state with a contrast checker. A combination that looks acceptable in the preview can still fail on another display or when a user applies forced colors.

Test the result beyond the square shape

The generator’s preview is useful for checking the real element at desktop and mobile widths, but it only applies the styles it controls. Because square dimensions are added manually, inspect the final component in the page or component sandbox. Zoom can expose a box that is too small, translated text can expose missing room, keyboard testing can reveal a hidden focus ring, and touch testing can reveal controls that are difficult to hit.

  • Confirm that the outer box stays square at the widths and zoom levels the product supports.
  • Verify that long labels and icons remain centered or wrap according to the design.
  • Check the default, hover, active, disabled, focus, and forced-color presentations.
  • Confirm that an icon-only version still has an accessible name and that a native button has the correct type.

Understand what the visual generator handles

The CSS Button Generator is a baseline workbench rather than a complete design system. It works in the current browser tab, needs no framework, component library, image asset, or JavaScript runtime, and does not upload the design values. Colors must be six-digit hexadecimal values, numeric controls are bounded, and the simple shadow follows horizontal offset, vertical offset, and blur order, with nonnegative blur and restrained translucent black. It does not calculate contrast, create width or height rules, or invent hover, focus, active, loading, or disabled styles. Start from existing tokens when possible, then test the final button in context.

Related reading: Clip Path Generator for Large Text: Polygon CSS.