HTML JavaScript CSS
Advanced
60 mins
Teacher/Student led
180 points
What you need:
Chromebook/Laptop/PC or iPad/Tablet

Weather Web App

In this step-by-step lesson, you'll create a Weather Web App that displays real-time weather data for a specified location. You'll learn how to set up a project, add jQuery and Fontawesome, create an HTML structure, style the structure and headings, initialise JavaScript, fetch and display weather data from an API, and add a feature to toggle between Celsius and Fahrenheit. By the end, you'll have a fully functional, interactive Weather Web App.
Learning Goals Learning Outcomes Teacher Notes

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Set up the project

    In this lesson, you will create a Weather Web App that pulls real-time weather data based on a location and displays it in an engaging and interactive manner. You will learn how to fetch and display weather data using APIs and jQuery. By the end of this lesson, you will have a fully functional Weather Web App.

    To start, open CodePen and create a new pen. We will be using HTML, CSS, and JavaScript for this project.


    2 - Add jQuery

    In this step, we will add the jQuery library to our project. jQuery is a popular JavaScript library that makes it easier to work with HTML documents, create animations, handle events, and perform various other tasks on a web page.


    3 - Add Fontawesome

    In this step, we will add Font-awesome to our project. Fontawesome is a library of icons that we can use to make our Weather Web App more visually appealing. To add Fontawesome, we need to include its stylesheet in our CodePen.

    Once you add the Fontawesome stylesheet to your project, you can use Fontawesome icons in your HTML code by adding an <i> element with the appropriate class names. For example, to add a sun icon, you can use the following code:

    <i class="fas fa-sun"></i>

    This will display

    You can find more icons and their class names on the Fontawesome website.


    4 - Add HTML structure

    In this step, we will create the HTML structure for our Weather Web App. This structure will include various elements to display the weather data, such as the location, date, forecast, temperature, and other weather parameters like wind, clouds, humidity, and pressure. We will also add a background image of the location we are showing the weather for.

    Add the following HTML code to the HTML section of your project:

    <div id='bg-img'>
      <div id='wrapper'>
        <h1><i class="fas fa-cloud-sun"></i> Weather App</h1>
        <div id='location'>
          <h2 id='currentLocation'></h2>
          <h4 id='currentDate'></h4>
        </div>
        <div id='main-data'>
          <img src='' alt="Weather icon"/>
          <p id='forecast'></p>
          <p id='currentWeather'></p>
        </div>
        <div id='temp'>
          <p id='currentTemp'></p>
          <p id='high-low'></p>
        </div>
        <div id='parameters'>
          <div>
            <span><i class='fas fa-wind'></i> Wind</span>
            <span id='wind'></span>
          </div>
          <div>
            <span><i class='fas fa-cloud'></i> Clouds</span>
            <span id='cloud'></span>
          </div>
          <div>
            <span><i class='fas fa-tint'></i> Humidity</span>
            <span id='humidity'></span>
          </div>
          <div>
            <span><i class='fas fa-gauge-high'></i> Pressure</span>
            <span id='pressure'></span>
          </div>
        </div>
      </div>
    </div>

    Here's a brief explanation of the main HTML elements:

    • bg-img: This div will contain the background image of the location we are showing the weather for.
    • wrapper: This div wraps all the content of our Weather Web App.
    • location: This div displays the current location and date.
    • main-data: This div contains the weather icon, forecast, and current weather description.
    • temp: This div displays the current temperature and high-low temperatures.
    • parameters: This div contains the weather parameters like wind, clouds, humidity, and pressure.

    5 - Style the structure and headings

    In this step, we will add some CSS to style our Weather Web App. The provided CSS code will style the background, text, and layout of the web app. It will also create a responsive design that looks good on different devices.

    Add the following code into the CSS section of your project:

    body {
      font-family: Arial, sans-serif;
      color: #fff;
      margin: 0;
      padding: 0;
      background: #e0e0e0;
    }
    
    #bg-img {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100vh;
      background: linear-gradient(to right, #3a7bd5, #3a6073);
      background-size: cover;
      background-position: center;
    }
    
    #wrapper {
      background: rgba(0, 100, 100, 0.9);
      padding: 20px;
      border-radius: 10px;
      width: 300px;
    }
    
    h1, h2, h4, p {
      margin: 0;
      padding: 0;
      text-align: center;
    }
    
    h1 {
      margin-bottom: 20px;
    }
    
    h2 {
      font-size: 24px;
      margin-bottom: 10px;
    }
    
    h4 {
      font-size: 16px;
      margin-bottom: 20px;
    }

    Here's a brief explanation of what the CSS code does:

    • body: Sets the font, color, margin, padding, and background color for the entire page.
    • #bg-img: Styles the background image container with a linear gradient, centers the content, and sets the height to 100% of the viewport height.
    • #wrapper: Styles the main content wrapper with a semi-transparent teal background, padding, border-radius, and a fixed width.
    • h1, h2, h4, p: Sets the margin, padding, and text alignment for the headings and paragraphs.
    • h1: Adds a bottom margin to the main heading.
    • h2: Sets the font size and bottom margin for the secondary heading.
    • h4: Sets the font size, bottom margin, and color for the tertiary heading.

    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of DigitalSkills.org. Unauthorised use, copying or distribution is not allowed.
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more