How to make a div tag clickable

In Html we have the Anchor tags which is a clickable element, so if you have a div tag or any other tag like span or p you can make it clickable simply by wrapping it with an anchor tag. Let's see an example,

Example :

<div style="background-color:#09C;color:#fff;padding:20px;margin:20px">Div tag : Not Clickable</div>

Result :

Div tag : Not Clickable

Now simply wrap the above div with an anchor tag, note if you have some text within your div tag and you don't want it to be underlined as in case of a hyperlink, just add textdecoration:none in the style tag.

Example :

<a href="" style="text-decoration:none">
<div style="background-color:#09C;color:#fff;padding:20px;margin:20px">This is my div tag : Clickable</div>

Result :

This is my div tag : Clickable

Topics Coverage:

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.

Follow Us: GitHub | Facebook | Twitter | Instagram