**Introduction to HTML, CSS, and JavaScript for Front-End

Welcome to Day 3 of your Web3 developer journey! Today, you'll dive headfirst into the core technologies that power front-end development: HTML, CSS, and JavaScript. You'll learn the fundamental building blocks of structuring, styling, and adding interactivity to web pages.

Learning Objectives

  • Understand the basic structure of an HTML document and create simple HTML elements.
  • Apply CSS to style HTML elements, including colors, fonts, and layout.
  • Write basic JavaScript code to add interactivity to a web page, such as responding to button clicks.
  • Differentiate between HTML, CSS, and JavaScript and their roles in front-end development.

Lesson Content

HTML: The Structure of Your Web Page

HTML (HyperText Markup Language) is the backbone of any website. It uses tags to define the structure and content of your page. Think of it like the skeleton of a human body.

Key Concepts:
* Tags: Enclosed in angle brackets, like <h1>, <p>, <img>. They tell the browser what kind of content to display.
* Elements: A tag and its content (e.g., <h1>Hello, World!</h1>).
* Attributes: Provide extra information about an element (e.g., <img src="image.jpg" alt="Description of the image">).

Example:

<!DOCTYPE html>
<html>
<head>
  <title>My First Web Page</title>
</head>
<body>
  <h1>Welcome!</h1>
  <p>This is a paragraph of text.</p>
  <img src="example.jpg" alt="Example Image">
</body>
</html>
  • <!DOCTYPE html>: Declares the document as HTML5.
  • <html>: The root element, encompassing everything.
  • <head>: Contains meta-information about the page (e.g., the title, links to CSS).
  • <title>: The title that appears in the browser tab.
  • <body>: Contains the visible content of the page (headings, paragraphs, images, etc.).
  • <h1>, <p>, <img>: Example HTML elements.

Quick Check: What does HTML stand for?

CSS: Styling Your Web Page

CSS (Cascading Style Sheets) controls the visual presentation of your HTML content. It's like the skin and clothing of the skeleton.

Key Concepts:
* Selectors: Target HTML elements you want to style (e.g., h1, .my-class, #my-id).
* Properties: Define the visual aspects (e.g., color, font-size, margin, padding).
* Values: The specific setting for a property (e.g., red, 20px, 10px).

Example:

/* Style for all h1 elements */
h1 {
  color: blue;
  font-size: 30px;
}

/* Style for elements with the class 'my-paragraph' */
.my-paragraph {
  font-family: Arial;
}

Linking CSS: You can link CSS to your HTML in the <head> section using the <link> tag:

<head>
  <title>My Styled Page</title>
  <link rel="stylesheet" href="style.css">
</head>

Or you can style directly in the HTML tag with the style attribute:

<h1 style="color: red;">Hello World!</h1>

Quick Check: Which tag is used to link a CSS file to an HTML document?

JavaScript: Adding Interactivity

JavaScript (JS) makes your web pages interactive. It's the brain and muscles of the operation. It allows you to respond to user actions, manipulate the content of the page, and communicate with servers.

Key Concepts:
* Variables: Hold data (e.g., let name = "Alice";).
* Functions: Blocks of reusable code (e.g., function greet(name) { console.log("Hello, " + name); }).
* Events: Actions that happen in the browser (e.g., a button click, a key press).
* DOM (Document Object Model): A representation of the HTML structure that JavaScript can manipulate.

Example:

<button id="myButton">Click Me</button>
<script>
  const button = document.getElementById("myButton");
  button.addEventListener("click", function() {
    alert("Button clicked!");
  });
</script>
  • document.getElementById(): Gets an HTML element by its ID.
  • .addEventListener(): Attaches an event listener to an element.
  • alert(): Displays a pop-up message.

Where to put JavaScript:
* Inside <script> tags, either in the <body> or the <head>. It's best practice to put it just before the closing </body> tag so the HTML loads first and the JavaScript doesn't block the page render.
* In an external .js file, linked using the <script src="script.js"></script> tag in your HTML.

Quick Check: What is the primary function of JavaScript?

HTML, CSS, and JavaScript: Working Together

HTML provides the structure, CSS provides the styling, and JavaScript provides the interactivity. They work together to create dynamic and engaging web pages.

Think of it this way:
* HTML: The words and layout of a book.
* CSS: The font, colors, and design of the book.
* JavaScript: The ability to turn pages, search for words, or click on a link within the book.

Here's how they might interact:
* HTML creates a button.
* CSS styles the button (e.g., colors, size).
* JavaScript adds functionality to the button (e.g., when clicked, it displays a message or updates the content on the page).

Quick Check: Which of the following is NOT a valid CSS property?

Progress
0%