FormsPremium

Border Animation

At rest the field has no frame; on focus its four sides draw one after another like a pen going round it, then unwind when you leave.

CSSFocusBorder

Updated

This effect is part of Effect.Labs — 846 vanilla effects, some free, some premium. Forms has 21 effects, including 2 free. Explore the category →

3 usage examples

Answer to an online escape game riddle — Vorlhaven — Border Animation example 1

① Answer to an online escape game riddle — Vorlhaven

WhenOn arriving at room 3, the "Your answer" field takes over by itself: its gold frame draws while the player rereads the riddle, the timer ticking at the top.
WhyThe stroke going round the field draws the eye to where the answer goes, with no blinking or arrow, and the gold tint matches the room's decor.
Settings--bda-color: #d4b06a on the root, --bda-width: 100% next to the Submit button. On a real page, autofocus on the field; in the capture, the scene script calls focus(), types the answer and starts again.
Sign-up questionnaire, one question per screen — Pelmorin — Border Animation example 2

② Sign-up questionnaire, one question per screen — Pelmorin

WhenThe new user answers "What is your first name?" and presses Enter: the next question replaces the previous one and the frame draws around its empty field.
WhyWith a single question on screen, the frame drawing at each step signals that a new field is waiting, better than a mere text change.
SettingsThree .bda-field in one root, only one shown; the scene enlarges .bda-caption to 22 px to turn it into the question. A keydown listener on Enter moves focus to the next field.
Quantity edited in a stock table — Corvasse — Border Animation example 3

③ Quantity edited in a stock table — Corvasse

WhenThe storekeeper double-clicks a quantity: the cell becomes an 84 px field, the number is selected and a green frame goes round it. Enter or a click elsewhere saves.
WhyIn a dense table, the cell being edited must stand out without widening the column; the drawn frame takes the place of the existing borders.
Settings--bda-color: #4ade80, --bda-width: 84px, no .bda-caption: the name comes from an aria-label such as "Quantity CV-1042". inputmode="numeric", text right-aligned by the scene, 52 px rows.

How it works

The .bda-input field sits in a .bda-box set to position: relative, followed by four empty <span class="bda-edge">. Each is a 2 px stroke pinned to one edge: .bda-top anchored top-left, .bda-right top-right, .bda-bottom bottom-right, .bda-left bottom-left. At rest their length is zero, hence a field with no border, just a rgba(255, 255, 255, .03) fill.

On focus, the .bda-input:focus ~ .bda-… selector takes the horizontal strokes to width: 100% and the vertical ones to height: 100%. Since each stroke grows from its anchor point, the top runs left to right, the right side goes down, the bottom comes back left and the left side climbs up. Each segment lasts 0.3 s and starts after a 0, 0.1, 0.2 then 0.3 s delay: the frame is complete in 0.6 s.

The same delays apply when the field is left, the strokes withdraw into their original corner in the same order. The colour comes from --bda-color (default #6366f1). The .bda-caption text above the field is its visible label; the .fx-0283-root root is only a 300 px tall presentation background.

Accessibility

  • Label: "Your first name" sits in the <label> that contains the field, stays visible while typing and gives screen readers its name. The four strokes carry aria-hidden="true".
  • Inside a form: name="given-name" and autocomplete="given-name" are supplied, the value is submitted and the browser offers the saved first name.
  • Focus indicator: the full frame (2 px, indigo on dark, 4.4:1) is the focus indicator. It only exists during focus, which is the expected behaviour.
  • Reduced motion: prefers-reduced-motion: reduce removes the transition, the whole frame appears on focus.
  • Limit: at rest, with no border and an almost transparent fill, the field is hard to make out on a light page. Give it a stronger background in that case (see settings).

Browser compatibility

width and height transitions, the ~ selector and one CSS variable: Chrome 49, Firefox 31, Safari 9.1. Checked in Chromium, Firefox and WebKit with two copies in one form, by click, Tab and touch, at 390 px and with reduced motion. The example captures are driven by the scene script (simulated focus and typing, capture clicks that sometimes remove focus): that driving is not part of the code you buy.

Chrome 49+✓ Full (measured)
Firefox 31+✓ Full (measured)
Safari 9.1+✓ Full (WebKit engine measured)
Edge 79+✓ Full (Chromium engine)
Mobile iOS 9.3+✓ Full
Android Chrome 49+✓ Full (Chromium engine)

Without CSS variables the strokes lose their colour and focus becomes invisible: replace var(--bda-color, #6366f1) with the plain colour if you target very old browsers.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0283-root">
  <label class="bda-field">
    <span class="bda-caption">Your first name</span>
    <span class="bda-box">
      <input class="bda-input" type="text" name="given-name" autocomplete="given-name">
      <span class="bda-edge bda-top" aria-hidden="true"></span>
      <span class="bda-edge bda-right" aria-hidden="true"></span>
      <span class="bda-edge bda-bottom" aria-hidden="true"></span>
      <span class="bda-edge bda-left" aria-hidden="true"></span>
    </span>
  </label>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Frame colour (CSS — --bda-color) #6366f1 Applies to all four strokes at once. Set it on the root, the form or a single field.
Width (CSS — --bda-width) 280 px 100% to fill the column; the field never exceeds its parent thanks to max-width: 100%.
Duration per side (CSS — transition of .bda-edge) 0.3 s Down to 0.2 s gives a snappier stroke; keep the gap between sides shorter than the duration, or the stroke pauses at every corner.
Offset between sides (CSS — transition-delay) 0 / 0.1 / 0.2 / 0.3 s Setting all four to 0 makes the frame appear in one go, each side from its corner.
Thickness (CSS — height of .bda-top/.bda-bottom, width of .bda-right/.bda-left) 2 px Four values to change together.
Resting field fill (CSS — background of .bda-input) rgba(255, 255, 255, .03) On a light page, switch to #f1f5f9 and make the text colour dark, so the field stays visible before focus.
Visible label (HTML — .bda-caption) shown above Can be removed in a table cell or on a screen where the question is already written; then put aria-label on the field.

FAQ

The strokes are plain 2 px rectangles pinned to the box edges; they don't follow the field's border-radius: 8px. For a consistent look, set border-radius: 0 on .bda-input, or keep that contrast, which is part of the original design.
It withdraws in the same order (top, right, bottom, left) and each stroke shrinks back to its starting corner, because the delays also apply on the way out. For a reversed exit, use different delays on the :focus rule and on the resting rule.
Yes: replace <input> with <textarea class="bda-input"> and keep the four strokes right after it. The vertical strokes take height: 100% of the box, so they follow the area's real height.