Use the <a> or <div> buttons for image buttons

What is the best way to create image buttons?

Usage <a>: you must specify a background image on my image <a href="#">, however, the URL will be displayed in the browser status bar, which is a little annoying.

Using <div>: set a background image to my image, no url is displayed in the browser status bar, however you need to add cursor:pointerto .css

+3
source share
4 answers

I would not go to the div personally, because semantically the div is not a button. If you want a button that performs a JavaScript action, I would just use a tag <button></button>. You can put other HTML elements inside the button tag, like a div, and better semantically.

To repeat what @Richard JP Le Guen said, ideally you would also add these buttons with JavaScript so that people who don’t support JavaScript do not see them, or you can offer alternative functionality for those who don’t support JS.

+6
source

I prefer to use <a>it because the browser handles click events initially. Clickable <div>must require javascript to handle click events.

URL- . , / .

+1

; (<a>) . ( ), JavaScript , , .

<div> JavaScript, JavaScript .

+1

! CSS . "cursor: pointer" .:)

+1

All Articles