Courses / Mobile Application Development (CDE-315) – BS CS 5th Semester

Week 2 Lab 2 – Create a Mobile-Friendly Web Page with Headings, Images, Links and a Form

Week 2 – HTML5 for Mobiles · 120 min read · 11 MCQs to check yourself

Code a responsive mobile-first web page step by step

Objective

Build one responsive web page "My Department" with headings, an image, links (web, phone, email, map) and a registration form, and test it at phone, tablet and desktop widths. CLOs: CLO-1 (compare mobile web apps with native apps), CLO-4 (use modern tools – Chrome DevTools device mode, Lighthouse).

How this connects to CampusMate

This page is the mobile website of the department. In Lab 6 the CampusMate app opens a website with a button, and in Labs 6 and 11 it opens the dialer, Maps and email – the same jobs that the tel:, mailto: and map links do on this page. You will see that a web page can do a lot, but a native app can do more (sensors, notifications, offline storage).

Workflow

Step What you do File
1 Create the lab2 folder (see Tools) and write the HTML: header, sections, links, form index.html
2 Style it mobile-first with media queries style.css
3 Test on phone, tablet and desktop widths Chrome DevTools
4 Experiment: remove the viewport tag index.html

Tools

Any editor – VS Code (recommended, with the Live Server extension) or Notepad++; Google Chrome. Create a folder lab2 with index.html, style.css and an images folder containing campus.jpg (any photo, preferably under 300 KB).

Step 1 – index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Department of Computer Science</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <header>
    <h1>Department of Computer Science</h1>
    <nav>
      <a href="#about">About</a>
      <a href="#programs">Programs</a>
      <a href="#register">Register</a>
    </nav>
  </header>

  <main>
    <section id="about">
      <h2>About us</h2>
      <figure>
        <img src="images/campus.jpg" alt="Campus building" loading="lazy">
        <figcaption>Our campus</figcaption>
      </figure>
      <p>We offer BS Computer Science with modern labs for mobile and web development.</p>
    </section>

    <section id="programs">
      <h2>Programs</h2>
      <div class="cards">
        <article class="card"><h3>BS CS</h3><p>4 years, 8 semesters</p></article>
        <article class="card"><h3>BS SE</h3><p>Software Engineering</p></article>
        <article class="card"><h3>BS AI</h3><p>Artificial Intelligence</p></article>
      </div>
    </section>

    <section id="contact">
      <h2>Contact</h2>
      <ul class="links">
        <li><a href="https://developer.android.com" target="_blank" rel="noopener">Android Developers</a></li>
        <li><a href="tel:+92511234567">Call the office</a></li>
        <li><a href="mailto:cs@example.edu.pk?subject=Admission%20query">Email us</a></li>
        <li><a href="sms:+923001234567?body=Hello">Send SMS</a></li>
        <li><a href="https://maps.google.com/?q=33.6844,73.0479">Open in Google Maps</a></li>
      </ul>
    </section>

    <section id="register">
      <h2>Register for the open day</h2>
      <form onsubmit="return done(event)">
        <label for="name">Full name</label>
        <input id="name" name="name" type="text" required autocomplete="name">

        <label for="email">Email</label>
        <input id="email" name="email" type="email" required autocomplete="email">

        <label for="phone">Mobile number</label>
        <input id="phone" name="phone" type="tel" pattern="03[0-9]{9}" placeholder="03001234567" required>

        <label for="dob">Date of birth</label>
        <input id="dob" name="dob" type="date">

        <label>Gender</label>
        <div class="row">
          <label><input type="radio" name="gender" value="M" required> Male</label>
          <label><input type="radio" name="gender" value="F"> Female</label>
        </div>

        <label for="program">Program</label>
        <select id="program" name="program">
          <option>BS CS</option><option>BS SE</option><option>BS AI</option>
        </select>

        <label><input type="checkbox" required> I agree to the terms</label>
        <button type="submit">Submit</button>
      </form>
      <p id="msg"></p>
    </section>
  </main>

  <footer><p>&copy; 2026 Department of CS</p></footer>

  <script>
    function done(e) {
      e.preventDefault();
      document.getElementById("msg").textContent =
        "Thank you, " + document.getElementById("name").value + "! Registration received.";
      return false;
    }
  </script>
</body>
</html>

Step 2 – style.css (mobile first)

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, Arial, sans-serif; font-size: 1rem; line-height: 1.5; color: #1f2937; }
header { background: #0f766e; color: #fff; padding: 16px; }
header h1 { margin: 0 0 8px; font-size: 1.4rem; }
nav { display: flex; gap: 8px; flex-wrap: wrap; }
nav a { color: #fff; padding: 10px 14px; border-radius: 8px; background: rgba(255,255,255,.15); text-decoration: none; }
main { padding: 16px; max-width: 1000px; margin: auto; }
img { max-width: 100%; height: auto; border-radius: 12px; }
.cards { display: grid; grid-template-columns: 1fr; gap: 12px; }
.card { border: 1px solid #e5e7eb; border-radius: 12px; padding: 12px; }
.links a { display: inline-block; padding: 10px 0; }        /* bigger tap targets */
form { display: grid; gap: 8px; }
input, select, button { font-size: 1rem; padding: 12px; border-radius: 8px; border: 1px solid #cbd5e1; width: 100%; }
.row { display: flex; gap: 16px; }
.row label, form > label:has(input[type=checkbox]) { display: flex; align-items: center; gap: 6px; }
input[type=radio], input[type=checkbox] { width: auto; }
button { background: #0f766e; color: #fff; border: 0; min-height: 48px; }
footer { text-align: center; padding: 16px; color: #6b7280; }

/* Tablet */
@media (min-width: 600px) {
  .cards { grid-template-columns: 1fr 1fr; }
  header h1 { font-size: 1.8rem; }
}
/* Desktop */
@media (min-width: 1024px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  form { grid-template-columns: 1fr 1fr; }
  form button { grid-column: span 2; }
}

Step 3 – Test on different screens

  1. Open index.html in Chrome (or Go Live in VS Code).
  2. Press F12 → Ctrl + Shift + M (device toolbar). Test iPhone SE (375 px), Pixel 7, iPad (768 px) and Responsive while dragging the width. Note how the cards change from 1 → 2 → 3 columns.
  3. Toggle portrait/landscape with the rotate icon.
  4. On a real phone: with Live Server, open http://<PC-IP>:5500 on a phone connected to the same Wi-Fi (find the PC IP with ipconfig). Or drag the folder to app.netlify.com/drop or push to GitHub Pages for a free public link.
  5. Tap the email, phone, date and number fields – note the different keyboards. Tap the Call, Email, SMS and Maps links – they open the phone's apps (the same idea as Android implicit intents in week 6).
  6. Run Lighthouse (DevTools → Lighthouse → Mobile) and note the Performance and Accessibility scores.

Step 4 – Experiment

Remove the viewport meta tag, reload in device mode and record what happens (the page shrinks to ~980 px and media queries stop matching). Put it back.

Short and long questions

1. (Viva) Write the anchor links that open the dialer, the email app and Google Maps at given coordinates.

Model answer

Dialer: an a tag with href="tel:+92511234567"; email: href="mailto:cs@example.edu.pk?subject=Query"; maps: href="https://maps.google.com/?q=33.6844,73.0479". On phones these open the respective apps.

2. (Viva) Why do we use type="email" and type="tel" instead of type="text" on mobile forms?

Model answer

They show suitable on-screen keyboards (with @ for email, a numeric dial pad for tel), enable built-in validation and support autofill, making forms faster and more accurate on phones.

3. (Viva) What changed when you removed the viewport meta tag?

Model answer

The phone rendered the page as if it were about 980 px wide and zoomed out, so text became tiny and the mobile media queries did not apply.

4. (Viva) How can you test a web page on different mobile screen sizes without a phone?

Model answer

Use Chrome DevTools device mode (F12, then Ctrl + Shift + M) to choose phone/tablet presets, drag a responsive width, rotate orientation and throttle the network; Lighthouse can then audit mobile performance and accessibility.

This lesson ends with a quiz of 11 MCQs. Open the lesson on PrepOasis to take it and save your progress.

Previous: Week 2 Theory – HTML5 for Mobiles – Responsive Pages, Mobile Forms, Device APIs and PWAs · Next: Week 3 Theory – Android OS – Architecture, Application Framework and Application Development

All lessons in Mobile Application Development (CDE-315) – BS CS 5th Semester