Make Your HTML-Website Suitable for Mobile Devices (2024)

Introduction: Make Your HTML-Website Suitable for Mobile Devices

More by the author:

About: Nowadays attempting creating small apps to dive into the world of programming and Software Development More About sphere360 »

First I was not satisfied when I visited a desktop optimized Website on a smartphone.
The fonts are too tiny, you have pan and zoom in/out all the time, the links are always hard to target. So I had to do some research how to make a website mobile suitable in relation to the display size.
Responsive (Web)Design is one possible solution.

The Good:
-Only basic HTML/CSS knowledge is required
-No additional App Programming/Installation

The Bad:
-You can't make (easily)a CMS created Website into a responsive site.
-I haven't tried it yet, but there is a CMS OS Project with responsive functionality, take a look at: http://www.fork-cms.com/

Step 1: Some Illustration

A responsive website behaves like a spring that fits in any size of space. You can stretch and compress it. If you change the structure, the spring itself doesn't affect on number of foldings or windings (threads). The 'information' remains the same.

You don't have to write everything new. A HTML-file contains information of a website, the CSS file defines the layout structure.
That means you only have to add a new tag in an existing HTML file and extend the CSS Stylesheet.

Step 2: Tools You Need

Special software is not required. You can work with the included Windows/Linux Text Editor or use a Freeware Editior (eg. Notepad++, gedit....)
For this tutorial I reused a HTML design layout provided by SelfHTML (a HTML learning Site, unfortunately only in German).
http://de.selfhtml.org/layouts/nr10/index.htm
So I asked and got the permission from the author, big thanks to him!

Step 3: Add One Code Line in the HTML-File

At first you add a meta tag into your HTML-File between the <head></head> tags:
<meta name="viewport" content="width=device-width, initial-scale=1" />

This codeline defines the default zoom for mobile devices.

Step 4: Media Query for Mobile Devices

A media query has the structure like:
<code>
@media screen and (max-width: 481px){

/*write your CSS-Code here*/

}
</code>

'@media screen and (max-width: 481px)' defines the CSS layout for screen sizes with 481px max. (CSS Resolution) and below.
For example a FullHD smartphone (portrait view) has a width of 1080 pixels, but it's not the same like the CSS-resolution.
To convert the "smartphone pixels" into "CSS pixels" you have to consider the pixel ratio.
A 1080p smartphone has a pixel ratio of 3 => 1080/3 = 360px (CSS-resolution)
At wikipedia, there is a list of the most common mobile devices that shows the resolution + pixel ratio:
http://en.wikipedia.org/wiki/List_of_displays_by_pixel_density
Thanks to the testers!

So we take a look at 'screen.css' (located at .../CSS/screen.css) and add a media query with new structure definitions after the existing CSS definitions.
The other css files are for older browser versions and for printing purposes.

Step 5: Use Dynamic Units to Keep the Site Responsive

In some cases it's better to use percent units or avoid static px, inch, em...etc.
Percent statements allow to keep the site flexible in relation to the screen size.

In this case I've deleted/commented the static 640px width in the "#body" element.

Step 6: Define a New CSS-Structure for the Navigation Links

To ease targeting the links I have added some margin and padding spaces between them.
The borders (border: 1px solid white;) around the link-elements give the look of buttons.

You can align the navigation elements to the left, right or center, like shown in the second image.

Step 7: Summarize All Textcolumns Into One Single Column

In portrait view a smartphone has not much horizontal space. So you have to stack the columns into one column vertically. In this example we have two textcolumns "#main" and "#subnav".

If you "float" both columns to the left, the "#subnav" column stacks on the top of the "#main".
I have defined the two columns with the same structure definitions, so that they have the same width, alignment and margin spaces.

~2.7% margin space seems to be visually more accurate (compare the border space on the left and right). Unfortunately I don't know where the ~0.6% have gone. Sometimes you have to estimate and experiment with the values.

Step 8: Test and Finalize Your Website

Testing is important, every (mobile) browser has a slightly different behaviour.

Testing Methods:

-The best way to test a responsive website is to use real mobile devices. You can go to an electronics store to check out your site with several kinds of smartphones and tablets.

-You can use an emulator to test a website, take a look at:
http://www.mobilexweb.com/emulators

-Firefox/Chrome has a built-in Development-Tool, so you can check out the look of a website in various screen-sizes, but it doesn't simulate a real mobile device.

FF: start the tool by pressing Ctrl+Shift+Mand select the screen size
Chrome: First you start the developer tools by pressing Ctrl+Shift+I. A cog-wheel appears right-below of the dev-screen. Click on the Cog Icon and goto the overrides tab. Select User Agent and Device Type.

Sometimes CSS definitions have to be written in a seperate CSS File for a certain (mostly older) browser. My tutorial is not perfect, it doesn't probably work perfectly on some browsers. So it's your turn to improve the code.

At last here is the edited html-layout of this tut attached as zip.

Attachments

  • nr10_edited.zip

    Download

Make Your HTML-Website Suitable for Mobile Devices (2024)

FAQs

How to make an HTML website mobile friendly? ›

How to make a mobile-friendly website
  1. Step 1: Make the design responsive. ...
  2. Step 2: Avoid large chunks of text. ...
  3. Step 3: Choose button size and placement. ...
  4. Step 4: Include a search function. ...
  5. Step 5: Optimize image sizes. ...
  6. Step 6: Eliminate pop-ups. ...
  7. Step 7: Improve loading speeds. ...
  8. Step 8: Use Viewport meta tag.
Oct 19, 2022

How do I make an HTML form mobile friendly? ›

Example
  1. width: 100%; padding: 12px; border: 1px solid #ccc; ...
  2. padding: 12px 12px 12px 0; display: inline-block;
  3. background-color: #04AA6D; color: white; padding: 12px 20px; ...
  4. border-radius: 5px; background-color: #f2f2f2; padding: 20px;
  5. float: left; width: 25%; ...
  6. float: left; width: 75%; ...
  7. content: ""; display: table;

How to make a website compatible with a mobile device? ›

Mobile website design best practices
  1. Use a responsive design. A responsive mobile web design is the best way to ensure that your website looks good on all devices. ...
  2. Keep it simple. ...
  3. Use large buttons. ...
  4. Avoid using pop-ups. ...
  5. Use fonts that are easy to read. ...
  6. Optimize your images. ...
  7. Use short forms. ...
  8. Include a call-to-action.

How do I convert my website to mobile friendly? ›

Conclusion
  1. Optimize your site's speed and enable Accelerated Mobile Page (AMP)
  2. Utilize media queries and the viewport meta tag.
  3. Use standard fonts.
  4. Optimize your images and use percentages instead of pixels.
  5. Space out the links and optimize button placement.
  6. Reduce the number of pop-ups.
Apr 2, 2024

Why is my website not mobile friendly? ›

Your Website Isn't Mobile Responsive

This means the website doesn't proportionally resize for varying screen sizes. Responsive design isn't the only approach to mobile optimisation, but it is the one Google recommends. It also makes a lot of sense from an SEO perspective.

How to convert a non-responsive website into responsive? ›

For many sites, the steps below, which explain how to make a website responsive, can help you get started with the basics.
  1. Determine How Your Site Is Used by Visitors. ...
  2. Make Images Responsive. ...
  3. Include Media Queries. ...
  4. Define Your Breakpoints. ...
  5. Make Text Responsive. ...
  6. Optimize Form Fields.
Sep 17, 2020

Can HTML be used on mobile? ›

Yes, you can run HTML on mobile. After creating an HTML file using a code editor app, you can view the webpage by opening the HTML file in your mobile web browser.

Is it possible to use HTML in mobile? ›

There are several apps available for mobile devices that can be used to open HTML files. These include HTML Viewer, WebMaster's HTML Editor Lite, and DroidEdit. HTML Viewer is a free app available for both Android and iOS devices.

How to create a mobile friendly form? ›

When it comes to designing mobile-friendly forms, here are five quick tips to make your life easier:
  1. Remove any unnecessary sections.
  2. Use drop-down lists when possible.
  3. Make sure your submission buttons are easy to press.
  4. Ensure your forms load fast.
  5. Test your forms before you publish them.

Can I convert my website to mobile app? ›

Yes, app builders like webtoapp. design allow anyone to transform websites into apps without coding. As a user, you need no special knowledge, since webtoapp. design takes care of everything technical.

What is it called when a website is mobile friendly? ›

What is a phone ready website design called? There are two different types of mobile friendly (phone ready) design: Responsive or Adaptive. With responsive design the web site is designed to expand and shrink depending on the size of the screen the user has the design itself is fluid.

How to resize web pages to fit screen on phone html? ›

Well, it's very easy.
  1. Add The Viewport Metatag. <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1"> ...
  2. Set CSS Variable. const resizeOps = () => { document. ...
  3. Adjust Your CSS. html, body { height: 100vh; height: calc(var(--vh, 1vh) * 100); }
Jul 9, 2020

How to resize web pages to fit screen on phone? ›

Set Page Zoom for all webpages
  1. On your Android device, open Chrome .
  2. Tap Settings. Accessibility.
  3. Turn on Show Zoom.
  4. Exit Settings.
  5. Use the slider to zoom in and out of the page.

Top Articles
Latest Posts
Article information

Author: Msgr. Benton Quitzon

Last Updated:

Views: 5876

Rating: 4.2 / 5 (43 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Msgr. Benton Quitzon

Birthday: 2001-08-13

Address: 96487 Kris Cliff, Teresiafurt, WI 95201

Phone: +9418513585781

Job: Senior Designer

Hobby: Calligraphy, Rowing, Vacation, Geocaching, Web surfing, Electronics, Electronics

Introduction: My name is Msgr. Benton Quitzon, I am a comfortable, charming, thankful, happy, adventurous, handsome, precious person who loves writing and wants to share my knowledge and understanding with you.