Making a div element clickable in HTML

To make an element, for example a <div>, clickable in HTML, you can use the following code:

<div onclick="location.href='#';" style="cursor: pointer;">

We simply add the onlcick event and add a location to it. Then, additionally and optionally, we add a cursor: pointer to indicate to the user the div is clickable. This will make the whole div clickable.


Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.


3 thoughts on “Making a div element clickable in HTML

  1. Lovely. Thanks, Thomas, the tip is much appreciated. I’m rebuilding my web site and have been scratching my head over this, and searching the web, for a solution, for hours. It seems that there are crowds of ‘coders’ infesting cyberland whose main aim in life is to make things more complicated than is necessary.


Leave a Reply

Your email address will not be published. Required fields are marked *