maillard.dev
creating websites is a passion
descriptive text

Goodbye Lightbox, Hello Dialog.

For a long time, frameworks were used to create lightboxes. Recently, with a little Javascript, you can do without a whole line of external code and implement the whole thing yourself without ease.

The <dialog> HTML tag is a versatile element that can be used to create a lightbox or modal window effect on a webpage. This tag provides a convenient way to display additional content or interactive features without navigating away from the current page. Let’s explore how the <dialog> tag can be used effectively as a lightbox.

A lightbox is a common UI pattern that presents content on top of the current page, dimming the background and focusing the user’s attention on the displayed content. Traditionally, lightboxes have been implemented using JavaScript and CSS, but with the introduction of the <dialog> tag in HTML5, creating lightbox-like functionality has become easier.

The <dialog> tag simplifies the implementation of lightbox functionality by providing a native HTML element dedicated to this purpose. However, it’s worth noting that browser support may vary, particularly in older versions. To ensure compatibility, it is advisable to include JavaScript fallbacks or use a JavaScript library specifically designed for creating lightboxes, such as Lightbox2 or Fancybox.

Be creative. Let me hear about your experience.

Further read a11y-dialog
Picture by Startaê Team, Brasilia

Back to blog