SVG as a submit button

SVG is a great format for your web graphics and icons especially. There is a small trick how to use an inline svg image as a submit button inside your form.

First thing to do is to wrap your image inside a label tag together with the submit button.

<form action="/search/" class="hide-submit" method="GET" >
  <input name="q" type="text" />
    <input type="submit" />
    <svg xmlns="" ...>
      <path d=" ..." />

The label associates these two elements together, so if you click one of them it acts like you clicked on the another as well.

Lastly we need to hide the actual submit button with a simple CSS.

form.hide-submit input[type="submit"] { display: none;}

And we have an inline svg image that behaves like a submit button without any use of javascript.


Would you like to get the most interesting content about programming every Monday?
Sign up to Programming Digest and stay up to date!