Web Design Basics

Module Goals

By the end, students should be able to:

  • Explain the role of HTML, CSS, and JavaScript.
  • Read and edit a basic webpage file structure.
  • Use browser developer tools to inspect and debug pages.
  • Build a small interactive page from starter code.
Web Stack

Three parts work together to make a webpage

HTML

The content and structure.

CSS

The appearance and layout.

JavaScript

The logic and interaction.

A strong web page separates meaning, style, and behavior so each part is easier to update.

Files

Project structure helps the browser find everything

Most projects keep HTML in the main folder and place CSS, JavaScript, and image assets in their own folders.

Start by finding index.html. It is usually the main page opened by the browser and is commonly used by GitHub Pages.

Example webpage file structure
HTML

HTML describes structure and content

HTML uses elements to describe what content is: headings, paragraphs, images, links, lists, sections, forms, and buttons.

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My Page</title>
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    <h1>Hello, 5041!</h1>
    <script src="js/script.js"></script>
  </body>
</html>
HTML Tags

HTML elements are building blocks

HTML tags structure web pages and format content for web browsers.

Opening tag

Starts an element, like <h1>.

Content

The text, image, link, or item shown on the page.

Closing tag

Ends an element, like </h1>.

<h1>Hello, 5041!</h1>
Common Tags

These elements show up constantly

<h1>-<h6>

Headings organize page sections.

<p>

Paragraph text for readable content.

<a>

Links to pages, files, or websites.

<img>

Displays images with alt text.

<button>

Clickable action on the page.

<form>

Collects user input.

Interactive Tool

Try writing HTML

Type HTML in the editor and run it to see the preview update.

HTML Editor

Preview

CSS

CSS controls design

CSS chooses colors, fonts, sizes, spacing, layout, and responsive behavior.

body {
  font-family: Arial, sans-serif;
  background: #1f1f1f;
  color: white;
}

.card {
  padding: 1rem;
  border-radius: 12px;
}
Adding CSS

Use a separate CSS file when possible

Inline or internal

CSS can be written directly in HTML, but it gets harder to reuse and maintain.

External file

A better practice is to link a separate CSS file inside the <head>.

<link rel="stylesheet" href="css/style.css">
Selectors

Selectors tell the browser what to style

CSS selectors can target groups of elements, specific classes, or unique IDs.

Element

p targets all paragraphs.

Class

.card targets anything with class="card".

ID

#main-title targets one unique element.

p { font-size: 40px; }
.card { border: 3px solid rgb(100, 50, 50); }
#main-title { color: #980000; }
Interactive Tool

Try writing CSS

Change the CSS in the style section and run the page.

CSS + HTML Editor

Preview

Box Model

Every element is a box

CSS box model diagram

The CSS box model treats every HTML element as a box made of content, padding, border, and margin.

These layers determine the element’s size and the space around it.

Layout Tools

Flexbox and Grid arrange content

CSS layout tools control how elements are arranged and spaced on a webpage.

Flexbox

Best for arranging items in one row or one column.

Grid

Best for two-dimensional layouts with rows and columns.

Interactive Tool

Flexbox vs. Grid

Edit either example to see how the layout changes.

Flexbox

Grid

Responsive Design

Pages need to work at different sizes

Screen sizes vary and browser windows can be resized during use.

Responsive pages adjust to different display sizes.

@media only screen and (min-width: 400px) { ... }
@media only screen and (min-width: 700px) { ... }
@media only screen and (min-width: 1000px) { ... }
JavaScript

JavaScript adds behavior

JavaScript can respond to clicks, update text, validate forms, fetch data, and change the page without reloading.

const button = document.querySelector('#refresh');

button.addEventListener('click', function () {
  console.log('Refresh requested');
});
Adding JavaScript

Link JavaScript after the page content

Directly in HTML

Useful for quick tests, but can become messy.

Separate JS file

A better practice is to add a separate JavaScript file near the end of the body.

<script src="js/script.js"></script>
Learning JavaScript

Spend time with the basics

If JavaScript is new to you, practice variables, functions, conditionals, events, arrays, and DOM selection.

These skills make interactive websites and web apps possible.

Troubleshooting

Debugging is a normal part of web design

  • Test one small change at a time.
  • Inspect elements and CSS with Developer Tools.
  • Confirm file paths, links, and filenames.
  • Refresh the page and clear the browser cache.
  • Use console.log() to check JavaScript values.
  • Validate HTML and CSS syntax.
  • Test in multiple browsers and screen sizes.
Beginner Bugs

Most errors are small but specific

Wrong file path

The browser cannot find the CSS, JS, or image file.

Missing punctuation

One missing quote, bracket, or semicolon can break code.

Selector mismatch

JavaScript or CSS targets a class or ID that does not exist.

Cache confusion

The browser shows an older copy. Hard refresh and test again.

Browser DevTools

Use DevTools to inspect and debug

Open

Right-click a page and choose Inspect.

Elements

View and test HTML and CSS.

Console

Read JavaScript errors and test commands.

Network

Check file and API requests.

Mini Challenge

Build and debug a small page in JSFiddle

  1. Open JSFiddle in a new page.
  2. Copy in the HTML, CSS, and JavaScript starter code.
  3. Troubleshoot and fix the image problem.
  4. Create your own modification or add-on to the webpage.
JSFiddle IDE

An IDE combines coding, running, testing, and debugging

An Integrated Development Environment combines tools for writing, running, testing, and debugging code in one place.

JSFiddle is useful for simple web development and testing. Visual Studio Code is another development tool for local projects.

Starter HTML

Copy into JSFiddle

<main class="card">
  <h1>BEARY Viewer</h1>
  <p>Click the button to display BEARY the safety bear.</p>

  <button id="beary-button">Show BEARY</button>

  <div id="image-container"></div>
</main>
Starter CSS

Copy into JSFiddle

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: Arial, sans-serif;
  background: #1f1f1f;
  color: white;
}

.card {
  width: min(500px, 85%);
  padding: 30px;
  text-align: center;
  background: #303030;
  border-top: 6px solid #980000;
  border-radius: 10px;
}

button {
  padding: 12px 20px;
  border: none;
  border-radius: 6px;
  background: #980000;
  color: white;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
}

button:hover {
  background: #666666;
}

#image-container {
  margin-top: 24px;
}

#image-container img {
  width: 100%;
  border-radius: 8px;
}
Starter JavaScript

Copy into JSFiddle

const button = document.querySelector("#beary-buton");
const imageContainer = document.querySelector("#image-container");

button.addEventListener("click", function () {
  const bearyImage = document.createElement("img");

  bearyImage.src =
    "https://github.com/5041CyBears/training-modules/blob/main/assets/BEARY.png?raw=true";

  bearyImage.alt = "BEARY the Safety Bear";

  imageContainer.replaceChildren(bearyImage);
});
Debug Challenge

BEARY troubleshoot

The page loads, but clicking the button does not display the image. Find and fix the error.

Debugging Strategy

  1. Follow the code in the order it runs.
  2. Identify which HTML element each JavaScript selector is trying to find.
  3. Compare the selector to the element’s actual HTML id.
  4. Check the browser console for an error involving null.
Reveal Solution

The selector contains a misspelling. It uses #beary-buton instead of #beary-button.

const button = document.querySelector("#beary-button");
Customize

Make the page your own

  1. Change the page colors.
  2. Change the font or text size.
  3. Add a short safety fact.
  4. Add a caption below the image.
  5. Add a button to remove the image.
  6. Add a reset button.
  7. Hide the button after the image appears.
  8. Add a second animal image button.
  9. Make the layout responsive for smaller screens.
  10. Let the user enter a custom image URL.
Required Quiz

Pass to complete the module

Each question is on its own slide.

Answer all 20 questions, then grade the quiz. Score at least 18 out of 20 to unlock the completion certificate.

Before the Quiz

Enter your name

This name will appear on your completion certificate.

Quiz Question 1
1 of 20

What is the main role of HTML?

Quiz Question 2
2 of 20

What is the main role of CSS?

Quiz Question 3
3 of 20

What is the main role of JavaScript?

Quiz Question 4
4 of 20

Which file is usually the main webpage opened by a browser or GitHub Pages?

Quiz Question 5
5 of 20

Which tag is used for a paragraph?

Quiz Question 6
6 of 20

What does an opening tag do?

Quiz Question 7
7 of 20

Which selector targets a class named card?

Quiz Question 8
8 of 20

Which selector targets one unique ID named main-title?

Quiz Question 9
9 of 20

What are the parts of the CSS box model?

Quiz Question 10
10 of 20

Which layout tool is best for one row or one column?

Quiz Question 11
11 of 20

Which layout tool is best for rows and columns?

Quiz Question 12
12 of 20

What does a media query help with?

Quiz Question 13
13 of 20

Where should a separate JavaScript file usually be linked?

Quiz Question 14
14 of 20

What is DevTools useful for?

Quiz Question 15
15 of 20

What does console.log() help with?

Quiz Question 16
16 of 20

What should you check if an image or CSS file does not load?

Quiz Question 17
17 of 20

What is a common cause of JavaScript selector errors?

Quiz Question 18
18 of 20

What is JSFiddle useful for?

Quiz Question 19
19 of 20

What is the bug in the starter JavaScript?

Quiz Question 20
20 of 20

What is the best debugging habit?

Quiz Results

Grade the quiz

You need at least 18 out of 20 to unlock the completion certificate.

Not submitted.

After passing, advance to the final completion certificate.

5041 CyBear Robotics

Certificate of Completion

Presented to

Student Name

for successfully completing the

Web Design Basics Training Module

Complete after passing the required quiz.