Free ToolsGuidesCase StudiesResourcesAboutContact
Get Your Free AI Automation Audit Book a Free 30-Minute Strategy Call
Playground~/frontend Open editor

~/css/outline-border-generator

CSS Outline and Border Generator

GeneratorRuns in your browserFree · no sign-up

Combine a border and an outline on one element and see how they differ: set the width, style and colour of each, push the outline away with outline-offset, and round the corners. Ideal for designing visible focus rings.

Border

Outline

Focus ring
CSS

Using the CSS Outline & Border Generator

Border versus outline

A border is part of the box: it takes up space and pushes content inward. An outline is drawn outside the box and takes up no space at all, so adding or removing it never shifts the layout. That makes outlines the right tool for focus indicators and hover highlights.

Outline offset

outline-offset moves the outline away from the border (positive values) or inside it (negative values). A small gap of 2 to 4 pixels makes a focus ring stand out from the element itself, especially when the element and the ring share a colour.

Outlines follow rounded corners

Current browsers draw outlines that follow border-radius, so you no longer need box-shadow hacks for rounded focus rings.

Designing focus rings

Never remove focus outlines without a replacement: keyboard users need them to see where they are. Use :focus-visible so the ring appears for keyboard navigation but not on every mouse click, and keep it at least 2px with strong contrast.

Should I ever remove the focus outline?

Only if you replace it with something at least as visible. Keyboard users rely on the focus indicator to know where they are. A common pattern is :focus-visible, which shows the ring for keyboard focus but not for a mouse click.

Worked example: a focus ring that works on any background

Use a two-colour ring: a light outline with a dark box-shadow just outside it, or the reverse. One of the two colours will contrast with whatever is behind the element. An outline-offset of 2 or 3 pixels keeps the ring clear of the element's own border.

Frequently asked questions

Why does my border change the element's size?

Borders add to the size unless you set box-sizing: border-box, which includes them in the declared width and height.

Can an outline have different sides?

No. Outlines are the same on all four sides. Use borders or box-shadow for per-side styling.

What makes a good focus ring?

At least 2px, a 3:1 contrast against the surrounding colours, and a small offset.

Does an outline take up space?

No. Outlines are drawn outside the element without affecting layout, which is why they are ideal for focus states: showing one never moves anything on the page.

What does box-sizing: border-box change?

With border-box, the width you set includes the padding and border, so adding a border does not make the element wider. Most modern stylesheets set it for every element.