Christian Heilmann

Styling submit buttons or using links to submit a form?

Tuesday, January 3rd, 2006 at 4:32 pm

Common issues Sending Form data to the server can be achieved in several ways, all of them with their pros and cons. It is especially tricky to create a form that has to be accessible, look great and allow for internationalisation (i18n). This post discusses the different options and offers a JavaScript that works around most issues.

The most accessible and least pretty way to submit a form is via a submit button.

Pros:

  • they resize with the font settings
  • their text content is determined by the value attribute, therefore it is is easy to localise them

Contras:

  • You cannot style them consistently across browsers, and they cannot get rollover states 1

The other option is to use an input element with the type “image”, which enables you to use any image to submit the form

Pros:

  • You have total control over the look and feel

Contras:

  • Whilst applying a proper alternative text makes the images accessible to blind visitors, images don’t scale when the font size gets changed, which means they are not 100% accessible.
  • i18n can become a maintenance issue, as you need to create (or automatically generate via the backend) images for each language.

Together with JavaScript, text links can be used to submit a form.

Pros:

  • You have total control over the look and feel
  • Text links scale with the font settings
  • i18n is dead easy, as it is text content of the page, not even alternative text in attributes

Contras:

  • requires JavaScript to work

Putting them all together

If you use a small JavaScript to check the document for submit buttons and dynamically replacing them with text links, you’ll get the best of both worlds:

  • users without JavaScript will get normal submit buttons
  • users with JavaScript styled text links.

See the demonstration page and try it alternately with JavaScript on and off.

The script that replaces the submit buttons uses Unobtrusive JavaScript and allows you to define a special class to add to each of the replacement links. The links will also have the same ID as the original submit button and their value as text content.

Feel free to use it and report any issues/problems here.2

1 It is debateable if you should design your own form controls anyways, after all the users knows how forms looks in their environment and some browsers/operating systems offer rollover states for submit buttons.

2 One issue is that if you don’t have any submit or image button in the form you won’t be able to send the form by hitting the enter button on the keyboard. To counterwork this you might want to add another image button or alter the script to hide the submit buttons instead of replacing them.

Share on Mastodon (needs instance)

Share on Twitter

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

Dev Digest 146: 🥱 React fatigue 📊 Query anything with SQL 🧠 AI News

Why it may not be needed to learn React, why Deepfake masks will be a big problem and your spirit animal in body fat! 

Dev Digest 147: Free Copilot! Panel: AI and devs! RTO is bad! Pi plays!

Free Copilot! Experts discuss what AI means for devs. Don't trust containers. Mandated RTO means brain drain. And Pi plays Pokemon!

Dev Digest 148: Behind the scenes of Dev Digest & end of the year reports.

In 50 editions of Dev Digest we gave you 2081 resources. Join us in looking back and learn about all the trends this year.

Dev Digest 149: Wordpress break, VW tracking leak, ChatGPT vs Google.

Slowly starting 2025 we look at ChatGPT vs Google, Copilot vs. Cursor and the state of AI crawlers to replace web search…

Dev Digest 150: Shifting manually to AI.

Manual coding is becoming less of a skill. How can we ensure the quality of generated code? Also, unpacking an APK can get you an AI model.

My other work: