No history yet

Frontend Fundamentals

The Three Pillars of the Web

Every website or web application you use is built on three core technologies: HTML, CSS, and JavaScript. Think of them like building a house. HTML is the structural frame—the foundation, walls, and roof. CSS is the interior and exterior design—the paint, furniture, and landscaping. JavaScript is the electrical and plumbing—it makes things work, like flipping a light switch or turning on a faucet.

As a backend engineer, you're used to managing data and logic on the server. Frontend is about presenting that data and logic to the user in the browser. Let's break down each pillar.

HTML for Structure

HTML, or HyperText Markup Language, gives content structure and semantic meaning. It's not a programming language; it's a markup language. You use it to declare what something is, not what it looks like. For example, you mark a piece of text as a top-level heading, a paragraph, a list, or a link.

The browser reads this HTML and uses it to build the structure of the page. A well-structured HTML document is also crucial for accessibility, allowing screen readers and other assistive technologies to understand and navigate your content.

Think of HTML as the nouns of a page: a <header>, a <nav>, an <article>, a <button>. Each tag describes the content it contains.

Here is the basic skeleton of any HTML document. The <!DOCTYPE html> declaration tells the browser it's an HTML5 document. The <html> element is the root. The <head> contains meta-information like the page title, and the <body> contains the actual content the user sees.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My First Web Page</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <header>
    <h1>Welcome!</h1>
  </header>
  <main>
    <p>This is the main content.</p>
    <button id="action-button">Click Me</button>
  </main>
</body>
</html>

CSS for Presentation

CSS, or Cascading Style Sheets, controls how the HTML elements look. It handles layout, colors, fonts, and spacing. By keeping the styling separate from the HTML, you can change the entire look of a site by editing just one CSS file. This is the principle of separation of concerns in action.

CSS works by applying rules to HTML elements. A rule consists of a selector (which element to target) and a declaration block (what styles to apply).

/* This is styles.css */

body {
  font-family: sans-serif;
  background-color: #f0f0f0;
}

header {
  background-color: #333;
  color: white;
  padding: 1rem;
  text-align: center;
}

button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 5px;
}

In the example above, the body selector targets the <body> element, and the properties inside the curly braces set its font and background color. The <link> tag in the HTML file connects this stylesheet to the page.

JavaScript and the DOM

JavaScript is the programming language of the web. It brings interactivity to a page, allowing you to react to user actions, update content dynamically without reloading the page, and much more.

How does it do this? When a browser loads an HTML document, it creates a corresponding in-memory representation called the Document Object Model, or DOM. The DOM is a tree structure where each HTML element is a node. JavaScript can access and manipulate this tree.

JavaScript interacts with the DOM to find elements and change them. For instance, you can grab the button from our HTML and make it do something when clicked. This is called event handling. An "event" is any action the user performs, like a click, key press, or mouse movement. An "event listener" is a function that waits for a specific event to occur and then runs.

// This code would be in a <script> tag or a linked .js file

// Find the button element by its ID
const button = document.getElementById('action-button');

// Find the h1 element
const heading = document.querySelector('h1');

// Add a 'click' event listener to the button
button.addEventListener('click', function() {
  // When the button is clicked, change the heading's text
  heading.textContent = 'You clicked the button!';
});

In this snippet, document.getElementById() is a DOM method that finds an element. addEventListener() attaches a function to run when the 'click' event happens on our button. When it does, the textContent of the <h1> element is updated.

These three technologies, working together, form the foundation of virtually all user-facing experiences on the web.

Quiz Questions 1/6

What is the primary function of HTML?

Quiz Questions 2/6

In the 'house building' analogy for web technologies, CSS represents the interior and exterior design (paint, furniture, etc.).

Understanding how these pieces fit together is the first major step in becoming comfortable with frontend development.