- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add a button to an image with CSS?
Following is the code to add a button to an image with CSS −
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> img{ width: 100%; } div { position: relative; width: 100%; max-width: 400px; } div img { width: 100%; height: auto; } div button { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: rgb(64, 21, 133); color: white; font-size: 20px; padding: 24px 36px; width: 220px; border: none; cursor: pointer; border-radius: 5px; text-align: center; font-weight: bolder; font-family: monospace,sans-serif,serif; } div button:hover { color:yellow; } </style> </head> <body> <h1>Button on Image Example</h1> <div> <img src="https://i.picsum.photos/id/354/400/400.jpg"> <button class="btn">Button</button> </div> </body> </html>
Output
The above code will produce the following output −
On hovering over the button, the button will change color as shown −
- Related Articles
- How to add a border to an image with CSS?
- With CSS add transparency to a button
- How to add rounded corners to a button with CSS?
- How to add an image to a button (action) in JavaFX?
- How to add a navigation menu on an image with CSS?
- How to flip an image (add a mirror effect) with CSS?
- How to add a colored border to a button with CSS?
- How to add a form to a full-width image with CSS?
- Set Button on Image with CSS
- How to center an image with CSS?
- How to create an image gallery with CSS
- How to create an avatar image with CSS?
- How to shake/wiggle an image with CSS?
- How to create a "button group" with CSS?
- How to create a "more" button with CSS?

Advertisements