TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← Back to library

File Select Highlight

A file input changes its outline and icon on hover or keyboard focus.

Live Demo

Hover over the element or use Tab to focus.

Source Code

Copy the HTML, CSS or JavaScript you need for your project.

HTML
<label class="tbx-1043"><input type="file" accept="image/*,.pdf" aria-label="Choose file"><span class="tbx-1043__icon" aria-hidden="true">⇧</span><strong>Choose file</strong><small>Image or PDF</small></label>
CSS
.tbx-1043{position:relative;display:flex;width:min(268px,100%);min-height:135px;align-items:center;justify-content:center;flex-direction:column;gap:6px;border:2px dashed #aebed0;border-radius:11px;background:#fff;color:#48617a;font-family:system-ui;cursor:pointer;transition:border-color .25s,background .25s}
.tbx-1043 input{position:absolute;inset:0;width:100%;height:100%;opacity:0;cursor:pointer}
.tbx-1043__icon{display:grid;place-items:center;width:31px;height:31px;border-radius:50%;background:#e8f3ef;color:#2d7e75;font-size:23px;transition:transform .25s,background .25s}
.tbx-1043 strong{font-size:12px}.tbx-1043 small{font-size:10px;color:#8995a5}
.tbx-1043:is(:hover,:focus-within){background:#f2fbf8;border-color:#2a8a7e}.tbx-1043:is(:hover,:focus-within) .tbx-1043__icon{background:#d6f3e8;transform:translateY(-3px)}
.tbx-1043:focus-within{outline:3px solid #db9b5e;outline-offset:3px}
@media(prefers-reduced-motion:reduce){.tbx-1043,.tbx-1043__icon{transition:none}}

How to Use

Insert the HTML and add the CSS to your stylesheet. Adjust colors and sizes and avoid class conflicts.

Use Case

Useful for forms and contact sections.

Technical Notes

Keep controls usable on touch devices. Test keyboard focus and reduced-motion preferences.

Mobile:Ensure the interactive content remains accessible without hover on touch devices.

Browser:Uses modern CSS. Check behavior in the browsers you support.

Reduced Motion:Check that prefers-reduced-motion is respected.