The Wayback Machine - https://web.archive.org/web/20241118230602/https://www.geeksforgeeks.org/how-to-use-images-as-buttons-in-html/
Open In App

How to Use Images as Buttons in HTML?

Last Updated : 15 Nov, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Images as buttons means using pictures that you can click like buttons. They make websites look better and more interactive. Here are different ways to use Images as a button in HTML.

1. Using img Tag Inside Button Element

We can wrap the <img> tag inside a <button> element. This technique is useful for creating interactive buttons that feature custom images, while still utilizing the semantic and interactive features of the <button> element.

HTML
<button type="button"onclick="alert('Image Button clicked!')">
	<img src="https://media.geeksforgeeks.org/wp-content/uploads/20240905154658/gfglogo.jpg"
     	 alt="Button Image" style="width: 50px; height: 50px;">
</button>

Output

a1
Using img tag inside button element

2. Using <button> Element with Background Images

This approach involves applying a background image to a standard <button> element. It provides the flexibility of using CSS for styling and interaction effects. The button element in HTML creates a clickable button on your web page, By default, it has text or a label, but you can customize it to include images or styles.

HTML
<!DOCTYPE html>
<html>
  
<head>
   <style>
      .image-button {
         width: 100px;
         height: 100px;
         background-image: url(
'https://media.geeksforgeeks.org/wp-content/uploads/20240905154658/gfglogo.jpg');
         background-size: cover;
         border: none;
         cursor: pointer;
      }
   </style>
</head>

<body>
   <button class="image-button"
    onclick="alert('Button clicked!')">
   </button>
</body>

</html>

Output

a1
Using button element with background images

3. Using <input> Element with Image Type

We will use the <input> element with type="image". It creates an image-based submit button that can be used in forms. This approach is straightforward and adds a nice visual touch to you site. IN HTML, <input> element is used to create interactive controls in a web form.

HTML
<form action="/submit-url" method="post">
	<input type="image" src=
"https://media.geeksforgeeks.org/wp-content/uploads/20240905154658/gfglogo.jpg"
		alt="Submit" width="100" height="50">
</form>

Output


Next Article

Similar Reads

Bootstrap 5 Buttons Block buttons
Bootstrap 5 Block buttons are used to display the full-width responsive buttons. To make the block buttons, we will use .d-grid, and .d-flex classes. We can also use screen sizes classes to change the button sizes on different screen sizes. Block buttons used Classes: .d-flex: This class is used to display an element as a block-level flex container
2 min read
How to Display Validation Message for Radio Buttons with Inline Images using Bootstrap?
By default, Bootstrap 4 has various form features for radio buttons with images inline. Here HTML 5 has default validation features, However, for custom validation, we must use JavaScript or jQuery. Below are the approaches that would help in displaying validation messages for radio buttons with images inline: Table of Content Using Inline ImageUsi
4 min read
How to use multiple submit buttons in an HTML form ?
Using multiple submit buttons in an HTML form allows different actions based on the button clicked. Each submit button can trigger a unique server-side or JavaScript process while sharing the same form fields, enabling various functionalities within a single form structure. Syntax<form action="/DEFAULT_URL" method="post"> <!-- Input fields
2 min read
Bootstrap 5 Images Aligning Images
Bootstrap 5 Aligning Images are used to set the alignment to the image. We will use float or text alignment classes to set the alignment of images. We can use the .mx-auto margin utility class to center the block-level images. Aligning Images used Classes: .float-start: This class is used to set the position of an element to left..float-end: This c
2 min read
Bootstrap 5 Images Responsive images
Bootstrap 5 Responsive images are used to resize the images according to their parent element and screen sizes. It means, the size of the image should not overflow its parent element and will grow and shrink according to the change in the size of its parent without losing its aspect ratio. Responsive images using Class:.img-fluid: This class is use
1 min read
How to use SVG Images in CSS and HTML?
SVG, or Scalable Vector Graphics, is a special type of image format used for creating high-quality graphics. Unlike regular images, SVGs don't lose clarity when zoomed or resized, making them perfect for responsive web design. They are easy to edit, accessible, lightweight, and highly scalable. Additionally, SVGs can be searched and manipulated dir
4 min read
How to use buttons with icons using Pure CSS?
Incorporating icon fonts with Pure buttons is a simple task using Pure CSS. Since Pure CSS does not come with its own icon pack, we are using icon fonts from Font Awesome. Before creating buttons with icons first we must include the pure.css file into our HTML file directly from CDN. Then link the Font Awesome CSS files to your page. Example 1: The
2 min read
HTML | DOM MouseEvent buttons Property
The buttons property of mouse event is used to return a number. The number indicates which mouse button or mouse buttons were pressed when a mouse event was triggered. This property is usually used along with the onmousedown event. This property is read-only. Due to lack of browser support, you may want to look at the button property instead. Synta
2 min read
How to Create Text Reveal Effect for Buttons using HTML and CSS ?
Buttons are the most important user interface component for any website. It is very important to design the buttons in a creatively unique way. The text-reveal effect for a button is used when it is used to reveal some offer or exciting content for enhancing the user experience. Approach: The approach is to cover the button with a strip of the same
2 min read
How to add Radio Buttons in form using HTML ?
In this article, we will learn how to add Radio Buttons in form using HTML. We know that Radio Buttons are used to select only one option out of several options. It is generally used in HTML form. If we want to deselect any option we have to select another option in the case of a radio button. Approach: To add a radio buttons in a webpage, the HTML
1 min read
How to create a form with custom buttons in HTML ?
HTML form contains other form elements like text box, check box, radio button, submit button, and many more. For creating an HTML form, <form>________</form>tag is used as it is paired tag so starting and closing tags both are required. Other form elements are placed within these tags. It can be placed anywhere in the body tag of an HTM
3 min read
How to Prevent Buttons from Submitting Forms in HTML?
We will use different approaches for preventing buttons from submitting forms. There are several reasons where preventing the buttons from submitting forms, i.e., if the user hasn't completed all the required form fields, or added incorrect details in the form, etc. Below are the approaches to prevent buttons from submitting forms in HTML: Table of
3 min read
Why card images use data-src (not src) for image in Bootstrap 4 ?
Bootstrap 4 card images use src in image tags to providing the location to be loaded in the given image tag and data-src to provide additional information that can be used by JavaScript for improving the users' experience. For data-src and src tag we can conclude as follows: src: If you want to load and display a particular image, then use .src to
3 min read
How to use grid for images in bootstrap card ?
Images can be added to the Bootstrap card by simply using an img tag. But we cannot use the same method directly to place an Image Grid into the Bootstrap Card as it will be lead to a misaligned design. Therefore, to get a per-flow to place image Grid into Bootstrap Card. The perfectly aligned grid we need to add some CSS to our HTML code. Approach
2 min read
How to allow cross-origin use of images and canvas ?
In this article, we will see how to allow the use of the cross-origin for images and canvas, i.e., utilizing the images and canvas from the foreign website. To accomplish this task, the images can be utilized from other websites to our HTML document, simply by implementing the <img> tag and assign the URL to the src attribute. Although, most
6 min read
How to use imgur to host images in ReactsJS ?
Imgur is primarily used as an image-sharing service, where users post content through an interface provided by the company, just like Facebook or Instagram. But we can also post images to Imgur by accessing their APIs. So, in this article, we will discuss how to upload images to Imgur in React without relying on any other third-party library like A
2 min read
How to use document.images in JavaScript ?
In JavaScript, the document.images property returns a collection of all "<img>" elements within the current document. We can manipulate these images using various properties and methods. We will see how to work with document.images in JavaScript. ApproachFirst, create a basic HTML structure and add some images.Then use document.images to acce
2 min read
Understanding the Use of Images & Icons in UI Design
Images and icons are the visual elements that help ease recognition. These elements drive emotional attachment to the content. You must have seen websites using a balance of written content and visual elements. Images and icons create a unique visual identity of a product that has everything to do with its appearance and feel. Good use of visual el
8 min read
How To Use Local Static Images In Svelte?
Static images are stored locally within your project and can be accessed directly through the file path. In Svelte, you can use these static images in your components by importing them directly or referencing their paths within the public directory. In this article, we will explore two different approaches to using local static images in Svelte. St
3 min read
HTML Canvas Images
In this article, we will see HTML Canvas Images. We generally use images on our web page through <img> element. In this article, we will see HTML Canvas images in HTML and JavaScript. The drawImage() Method is used to embed images or video on Canvas. With this method, we can also change the height and width of the image and clip the image. Im
3 min read
How to Create Avatar Images using HTML and CSS ?
This article will show you how to create an Avatar Image with the help of HTML and CSS. An Avatar is a visual representation of a user, often used in user profiles or comment sections on websites. Here, we have created a GFG logo avatar image. This avatar has 100px width and height, and border-radius to 50%. Example: C/C++ Code &lt;!DOCTYPE htm
1 min read
HTML Background Images
HTML background images are graphics applied to the background of HTML elements, often used in webpage design for aesthetic or branding purposes. They're set using CSS background-image property, allowing for single or repeating images, gradients, or patterns to enhance visual appeal. Understanding HTML Background ImagesHTML Background Images allows
3 min read
How to Fix Images Not Showing in HTML?
One common issue web developers encounters is images not displaying on their HTML pages. This problem can be caused by the variety of reasons including the incorrect file paths, permissions issues and browser-related problems. In this article, we will explore several methods to diagnose and fix the issue of images not showing up in HTML. Common Cau
3 min read
Lazy Loading images in HTML
What is Lazy Loading? Lazy loading is a strategy to identify resources as non-critical and load these only when needed. It's a way to optimize web pages, which translates into reduced page load times. To read more about it:  https://www.geeksforgeeks.org/what-is-lazy-loading/ Generally images are larger in size, so lazy loading can be used to defer
2 min read
Create a Resize and Compress Images in HTML CSS & JavaScript
While using the GeeksforGeeks Write Portal to write articles, we need to upload the images. As we need to resize the image as per GeeksforGeeks's requirement, we search for different tools and websites on the internet to resize and compress the image. But, as a web developer, we can create our own image resize and compressor using HTML, CSS, and Ja
7 min read
How to create a drag and drop feature for reordering the images using HTML CSS and jQueryUI ?
In this article, we are given an images gallery and the task is to re-arrange the order of images in the list or grid by dragging and dropping. The jQuery UI framework provides a sortable() function that helps in re-ordering list items by using the mouse. With this functionality, the list items become interchangeable. The jQuery UI provides a sorta
3 min read
HTML DOM images Collection Property
The images collection property in HTML is used to return the collection of <img> elements in the document. It can be used for knowing the count of images inserted in the document using the <img> tag. The <input> elements with type = image are not counted in the image property. Syntax:  document.imagesProperty: It returns the numbe
4 min read
HTML Images
The HTML <img> tag is used to embed an image in web pages by linking them. It creates a placeholder for the image, defined by attributes like src, width, height, and alt, and does not require a closing tag. There are two ways to insert the images into a webpage: By providing a full path or address (URL) to access an internet file.By providing
7 min read
How to Arrange Images and Text in HTML?
In HTML, arranging images and text is essential for creating visually appealing and readable web pages. We can position images in various ways to achieve the desired layout, including the inline with text, above, below, or beside it. Understanding how to align and arrange these elements helps to enhance the user experience. We are going to arrange
6 min read
How to display Base64 images in HTML ?
Base64 is a widely used method for encoding binary data, such as images, into ASCII text. This enables embedding binary data, such as images, directly into HTML without needing separate image files. In the context of web development, Base64 encoding is often used to improve page performance, security, and compatibility by reducing the number of ext
4 min read
Article Tags :
three90RightbarBannerImg