Grow your CSS skills. Land your dream job.

What html element to use for buttons calling actions?

  • # January 7, 2014 at 9:23 am

    As far as I can tell the standard for this is an <a> tag, but it doesn’t really make much sense. Especially if you have nothing to put in the ‘href’ attribute so you end up making it ‘#’ or ‘javascript:void’ or something silly like that.

    To me the HTML button element kinda makes the most sense, though it can be a bit weird with styling and the fact that you have to specify type="button" to keep it from submitting a form is odd (and kinda comical.. button type button is not the default?)

    What do you guys like to use, and what do you think about the semantics?

    # January 7, 2014 at 9:34 am

    Use <button> it’s much friendlier on mobile

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button

    # January 7, 2014 at 4:11 pm

    Button is the appropriate element. If you don’t want to specify button, you can in the script that gets called when you press it use event.preventDefault()

    # January 8, 2014 at 9:21 am

    Wouldn’t you know it, Chris posted today….

    http://css-tricks.com/use-button-element/

    # January 8, 2014 at 9:44 am

    you have to specify type=”button” to keep it from submitting a form …

    Note: only if the button is inside a form.

    Dunno if that’s relevant to your use case, but I typically don’t have buttons in forms that aren’t for submitting the form.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".