TipsBlocks Web Technique Library

PRACTICAL WEB TIP

← Back to library

Triptych Focus Gallery

The selected photo widens within a three-panel gallery while its neighbors recede.

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
<div class="tbx-1270"><div class="triptych" aria-label="Three gallery works"><button type="button" class="pane one" aria-label="Project 1: Mountains"><span class="art" aria-hidden="true">△<em>01</em></span></button><button type="button" class="pane two" aria-label="Project 2: Architecture"><span class="art" aria-hidden="true">▥<em>02</em></span></button><button type="button" class="pane three" aria-label="Project 3: Sea"><span class="art" aria-hidden="true">≈<em>03</em></span></button></div><p>SELECT A FRAME</p></div>
CSS
.tbx-1270{width:100%;min-height:218px;box-sizing:border-box;padding:20px 18px;display:flex;justify-content:center;align-items:center;flex-direction:column;gap:12px;background:#1c2733;color:white;font-family:system-ui,sans-serif}.tbx-1270 *{box-sizing:border-box}
.tbx-1270 .triptych{width:min(340px,100%);height:153px;display:flex;gap:5px;overflow:hidden}.tbx-1270 .pane{min-width:0;flex:1;border:0;cursor:pointer;position:relative;overflow:hidden;display:grid;place-items:center;transition:flex .43s ease,filter .43s;padding:0;color:white}
.tbx-1270 .one{background:linear-gradient(145deg,#b6a7a2,#556c6c 70%)}.tbx-1270 .two{background:linear-gradient(145deg,#c5b98c,#8a7259 68%)}.tbx-1270 .three{background:linear-gradient(145deg,#6ea6aa,#22576e 75%)}
.tbx-1270 .pane:after{content:'';position:absolute;inset:0;background:linear-gradient(0deg,#09131ca3,transparent 56%);pointer-events:none}
.tbx-1270 .art{font:300 54px Georgia,serif;position:relative;z-index:1;transition:transform .4s}.tbx-1270 .art em{position:absolute;left:50%;bottom:-21px;transform:translateX(-50%);font:600 9px system-ui;letter-spacing:.13em}
.tbx-1270 .triptych:has(.pane:is(:hover,:focus-visible)) .pane:not(:hover,:focus-visible){filter:brightness(.72)}.tbx-1270 .pane:is(:hover,:focus-visible){flex:2.3}.tbx-1270 .pane:is(:hover,:focus-visible) .art{transform:scale(1.12)}.tbx-1270 p{font-size:9px;letter-spacing:.18em;opacity:.75;margin:0}
.tbx-1270 :focus-visible{outline:3px solid #ffd290;outline-offset:-3px}
@media(max-width:360px){.tbx-1270 .triptych{height:130px}.tbx-1270 .art{font-size:42px}}
@media(prefers-reduced-motion:reduce){.tbx-1270 *{transition:none!important}}

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 image galleries and portfolio galleries.

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.