ImageCompare

Compare two images side by side with a slider.


import ImageCompare from 'primevue/imagecompare';

Images are defined using templating with left and right slots. Use the style or class properties to define the size of the container.


<ImageCompare class="shadow-lg rounded-2xl">
    <template #left>
        <img src="~/assets/images/island1.jpg" />
    </template>
    <template #right>
        <img src="~/assets/images/island2.jpg" />
    </template>
</ImageCompare>

Apply responsive styles to the container element to optimize display per screen size.


<ImageCompare class="sm:!w-96 shadow-lg rounded-2xl">
    <template #left>
        <img src="~/assets/images/island1.jpg" />
    </template>
    <template #right>
        <img src="~/assets/images/island2.jpg" />
    </template>
</ImageCompare>

Screen Reader

ImageComponent component uses a native range slider internally. Value to describe the component can be defined using aria-labelledby and aria-label props.


<span id="image_label">Compare Images</span>
<ImageCompare class="shadow-lg rounded-2xl" aria-labelledby="image-label">
    ...
</ImageCompare>

<ImageCompare class="shadow-lg rounded-2xl" aria-label="Compare Images">
    ...
</ImageCompare>

Keyboard Support

KeyFunction
tabMoves focus to the component.
left arrowup arrowDecrements the value.
right arrowdown arrowIncrements the value.
homeSet the minimum value.
endSet the maximum value.
page upIncrements the value by 10 steps.
page downDecrements the value by 10 steps.