Reputation: 6531
I'm trying to learn the best way to create buttons via HTML/CSS. I was using clickable div's before, but looks like this was not the best idea ever.
What about button's? Or a href's
Which way is the best to go with today (html5 css3)?
Upvotes: 4
Views: 4020
Reputation: 4159
the best way to create buttons in html is to use or because when you buttons and inputs of type submit are used by default by the browser when you try to submit a form
for example :
<form action="somepage.php" method="POST">
<input type="text" name="name1">
<textarea></textarea>
<input type="submit" value="submit the form with a input of type submit">
</form>
only when the user click the submit button the form data are submited
BUT , when we use a or divs to play the role of buttons you need to call javascript and ask for help
FINNALY THE GOOD PRACTICE IS TO USE BUTTONS AND INPUT OF TYPE SUBMIT TO PLAY THE ROLE OF BUTTON EVERYTHING ELSE IS A CUSTOMIZATION THAT CAN INCREASE THE TIME TO LOAD THE PAGE
Upvotes: 0
Reputation: 4540
It depends on the behavior you are looking for. If its purpose is to link to another page then use an <a>
. If it is for submitting a form or doing some sort of post or get I would use a button.
There is a web based project management product called Basecamp. When they first launched they were using <a>
tags as delete buttons next to each individual task. Users who visited their internal pages while using the google web optimizer plugin for chrome were seeing all of their tasks marked as deleted. Google page optimizer looks for links in the page and triggers a click to pre-load future pages.
Let form follow function and you should be good to go :0)
Upvotes: 5
Reputation: 1878
One reason to favor buttons is that buttons are naturally better for accessibility, while using links, spans or other tags fails on that count. To get proper accessibility with those other elements, you have to use ARIA roles to fix them.
That's not a hack per se, since that's part of what ARIA roles are for. But it's an extra thing to learn about and make sure that you get right.
Upvotes: 0