How to Show Images on Click using HTML ?
Occasionally, web pages might contain images that are not relevant to the content of that page. These unusual images are loaded while the web page is loading, and this increases the loading time. More loading time on web pages can decrease the number of visitors.
- Create <img> element in the HTML code.
- Add style to <img> element and set display properties to none.
- Add button in HTML code which calls “show()” function when user clicks on it.
- Create <img> element with empty src attribute.
- Add HTML button which calls “show()” function, when user clicks on it.
Using Bootstrap Modal: We will use a bootstrap modal to show an image while clicking on the button. We need to integrate the bootstrap CDN with the HTML code to use it. We can add bootstrap CDN to our HTML file as added in the below example code.
- Add bootstrap CDN to HTML file.
- Create Bootstrap modal and add an image to the body of the modal.
- Create an HTML button to trigger a modal.
Please Login to comment...