Random Square Generator

Generates a random square with a random size, position, rotation, and fill/stroke color, rendered as a live SVG preview with a downloadable .svg file. The un-rotated square is always positioned to fit fully within the canvas before rotation is applied around its own center. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-26

Overview

Introduction

This tool generates a random square, rendered live as SVG, with a random size, position, rotation, and fill/stroke color.

It's a quick way to produce a simple placeholder shape for a design mockup, or to test how an SVG-consuming component handles a rotated rectangle.

What Is Random Square Generator?

A generator that draws a single random square inside a fixed SVG canvas, with a random side length (40-150px), a random position that keeps the un-rotated square fully inside the canvas, a random rotation angle, and independent random fill and stroke colors.

The result is rendered as an SVG <rect> element with a rotation transform, previewed live and available to copy or download as a standalone .svg file.

How Random Square Generator Works

The tool picks a random side length, then a random x/y position chosen so the un-rotated square fits entirely within the canvas.

A random rotation angle (0-359 degrees) is applied around the square's own center using an SVG `transform="rotate(...)"` attribute.

Independent random fill and stroke colors (as HSL color strings) and a random stroke width are applied before serializing the whole thing into a single SVG string.

When To Use Random Square Generator

Use it to generate a quick placeholder square shape for a design mockup or background decoration.

It's also useful for testing how an SVG-consuming component handles a rotated rectangle transform.

Features

Advantages

  • Guarantees the un-rotated square is fully contained within the canvas before any rotation is applied.
  • Produces a fresh, self-contained SVG string every time, ready to preview, copy, or download.
  • Independent fill, stroke, and stroke-width randomization for visual variety.

Limitations

  • A rotated square's corners can extend past the canvas edge, since only the un-rotated position is bounds-checked.
  • Side length, position, rotation, and colors are all randomized together; you can't currently lock one property while re-randomizing the others from the UI.
  • The canvas is a fixed 300x300 SVG viewBox, not resizable from the UI.

Examples

A random rotated square

Input

(no input; generated from settings: size=100, randomized position/rotation/color)

Output

<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" viewBox="0 0 300 300"><rect x="80" y="60" width="100" height="100" fill="hsl(160, 70%, 55%)" stroke="hsl(20, 70%, 55%)" stroke-width="3" transform="rotate(35 130 110)" /></svg>

A small, unrotated-looking square

Input

(no input; generated from settings: size=50, randomized position/rotation/color)

Output

<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" viewBox="0 0 300 300"><rect x="10" y="200" width="50" height="50" fill="hsl(280, 70%, 55%)" stroke="hsl(90, 70%, 55%)" stroke-width="1" transform="rotate(2 35 225)" /></svg>

Best Practices & Notes

Best Practices

  • Click Regenerate a few times if you specifically want a square that looks axis-aligned (a small rotation angle near 0 or 360 degrees).
  • Download the SVG file directly if you need to edit the square further in a vector graphics editor.

Developer Notes

Rotation is applied via SVG's own `transform="rotate(deg cx cy)"` attribute around the rect's computed center, rather than pre-rotating the four corner coordinates by hand, which keeps the underlying rect's x/y/width/height simple and axis-aligned before the transform is applied.

Random Square Generator Use Cases

  • Generating a placeholder square shape for a design mockup or prototype
  • Testing an SVG-consuming component's handling of rotated rectangle transforms
  • Producing a quick decorative background shape for a webpage

Common Mistakes

  • Assuming a rotated square always stays fully within the canvas; only the un-rotated position is bounds-checked.
  • Expecting to lock the size while re-randomizing rotation/color; the shipped tool fully randomizes everything together on Regenerate.
  • Forgetting to download or copy the SVG before regenerating, losing the current square.

Tips

  • Use the Random Circle Generator instead if you want a shape unaffected by rotation.
  • Compare a few regenerated squares side by side to see how differently the rotation angle changes the silhouette.

References

Frequently Asked Questions