How to set mobile input types in HTML?

Mobile devices have virtual keyboards. There is only limited space on the display to show the keyboard, so it will be helpful to the user to see only the needed keys. Using the right input type will dramatically improve the mobile experience.

There are many different input types available for html pages. Here are my favorites.

Input type text

The most common input type used. This will show the default keyboard on mobile devices.

Input type email

The input type email will show a virtual keyboard with easy access to the AT-Sign (@), the dot and sometimes there will be shown the most common top level domains, so you don’t have to enter “.com” letter by letter. The difference to the text input type is only marginal, but the mobile user experience will increase dramatically if you use the input type on the right field.

Input type tel

With the input type tel you can make it easy to enter a telephone number because you will get a virtual keyboard with a numeric keypad which includes everything you need to enter a phone number like sharp (#) or plus (+).

Input type number

The mobile input type “number” is correct if you have to enter numbers only. It is different from the input type tel and is the right type to enter numbers of barcodes, counters or anything else mainly containing digits but i think this type shouldn’t be using very often because in most cases tel will work better.

Input type password

If you ever made a login form you should know about it and I don’t want to describe it here, because there are millions of good descriptions about this input type in the World Wide Web.

Input type date

The name of the input type is date and this is what you can enter here. You don’t have to implement a JavaScript calendar widget or something else. Just set the tags attribute type to date and the mobile will do the rest for you. I like it.

Input type datetime

It is like the input type date, but it adds the time to the input. So you can enter date and time into your input field. Just replace the tag attrubte type from date to datetime and you have a input field for date and time.

Input type search

If your input field is a search field, you can use this type. It will show the (nearly) regular virtual keyboard with on exception. You get a search button direct on the virtual keyboard if you use this mobile input type. It is quite helpful and I use it often if I need a search function in my form.


Note: Some devices and virtual keyboards do not support every mobile input type. But If you user iOS or Android with a common keyboard, I’m sure you will get the right keyboard for your input type. And there are more…. but the above are the main types (IMHO).

Simple android showDialog example

A dialog can have a custom layout with buttons, text views, list, images, checkboxes, etc. You can create a layout for your dialog and show the dialog with the following simple method.

The showDialog method can be a part of your activity class. In that case you don’t need to explicitly declare the context as parameter. Just use this in case of context in the method body.

public void showDialog(Context context, String title, String message)
    final Dialog dialog = new Dialog(context);
    TextView messageBox = (TextView ) dialog.findViewById(;
    messageBox.setText (message);
    Button dialogButton = (Button) dialog.findViewById(;
    dialogButton.setOnClickListener(new OnClickListener()
        public void onClick(View v)
            // do something here when ok is pressed

Tha lyout filename is dialog_message.xml in this example.


You need to use HTML in your message. Simply referencing a String with HTML in your messageBox will not work. If you want to show html formated text in your dialog, you can use the following method to set the text of your text view.

    messageBox.setText (Html.fromHtml(message));

The following HTML tags are supported By TextView:

, , , 
, , ,
, , ,





, , ,

, , , , , , ,

Alternatively, you can use the great HTMLDialog library for you html dialog. ( The HtmlDialog lib simplifies the display of HTML in a DialogFragment. It is useful for displaying Open Source Licenses, EULAs, Terms of Service pages, etc.

The HTMLDialog is licensed under the Apache License, Version 2.0