Web Development Basics (HTML/CSS)

Watch this topic in 60 seconds

Free preview · Lesson 1

Understanding Web Development Basics (HTML/CSS)

Welcome to Web Development Basics: HTML & CSS!

Have you ever wondered how websites are made? From your favorite social media site to an online store, every single page on the internet is built using a combination of powerful technologies. In this lesson, we're going to unlock the secrets of two fundamental building blocks: HTML and CSS. Think of this as learning the alphabet and basic grammar before writing your first story!

What is Web Development? (The Big Picture)

Imagine you want to build a house. You wouldn't just start throwing bricks around, right? You'd need a blueprint, structural elements, and then finally, decorations. Web development is very similar! It's the process of creating websites and web applications that run on the internet.

Analogy: If creating a website is like building a house, then HTML is the blueprint and the foundational structure (the walls, roof, rooms), while CSS is the interior design and exterior paint (the colors, furniture, landscaping). Without the structure, there's nothing to decorate, and without decoration, the structure might look plain and uninviting.

Part 1: HTML - The Skeleton of the Web

What is HTML?

HTML stands for HyperText Markup Language. Don't let the long name scare you! In simple terms, HTML is the standard language for creating web pages. It provides the structure and content of a web page. Think of it as telling the web browser what elements should appear on the page – text, images, links, lists, and so on.

Analogy: HTML is like the skeleton of the human body. It defines where the head, arms, legs, and torso are. Without a skeleton, a body would be a shapeless blob. Similarly, without HTML, a web page would just be raw, unorganized text.

HTML Elements, Tags, and Attributes

HTML is made up of elements. An element typically consists of an opening tag, content, and a closing tag. Tags are keywords enclosed in angle brackets, like <p> for a paragraph.

  • Opening Tag: <tagname> (e.g., <p>)
  • Content: The actual information displayed (e.g., "Hello, world!")
  • Closing Tag: </tagname> (e.g., </p>)

Some elements, like the image tag <img> or the line break tag <br>, are called empty elements or self-closing tags because they don't have content between an opening and closing tag. They look like <img src="image.jpg" alt="Description"> or simply <br>.

Attributes provide additional information about an element. They are always specified in the opening tag and usually come in name/value pairs, like name="value".

<a href="https://www.google.com">Go to Google</a>

In the example above, href is an attribute of the <a> (anchor) tag, and its value is "https://www.google.com". This attribute tells the browser where to navigate when the link is clicked.

Basic HTML Document Structure

Every HTML page follows a basic structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First Web Page</title>
</head>
<body>
    <!-- Content goes here -->
    <h1>Hello World!</h1>
    <p>This is my very first paragraph on the web.</p>
</body>
</html>
  • <!DOCTYPE html>: This declaration defines that this document is an HTML5 document.
  • <html>: This is the root element of an HTML page. All other elements go inside this. The lang="en" attribute helps browsers and screen readers understand the language of the content.
  • <head>: Contains meta-information about the HTML page (like its title, character set, links to stylesheets, etc.). This content is NOT directly visible on the web page itself.
  • <title>: Sets the title of the page, which appears in the browser tab.
  • <body>: Contains all the visible content of the web page, such as headings, paragraphs, images, links, etc.

Common HTML Tags

  • <h1> to <h6>: Heading tags. <h1> is the most important, <h6> is the least.
  • <p>: Paragraph tag for blocks of text.
  • <a>: Anchor tag for creating hyperlinks (links to other pages or resources).
  • <img>: Image tag for embedding images. Requires src (source file path) and alt (alternative text for accessibility) attributes.
  • <ul> and <ol>: Unordered (bulleted) and Ordered (numbered) lists, respectively.
  • <li>: List item, used inside <ul> or <ol>.
  • <div>: A generic container for grouping other HTML elements. Often used for layout and styling with CSS.
  • <span>: A generic inline container for grouping small pieces of text or other inline elements.

Part 2: CSS - Making the Web Look Good

What is CSS?

CSS stands for Cascading Style Sheets. If HTML provides the structure, CSS provides the style. It describes how HTML elements should be displayed on screen, paper, or in other media. CSS saves a lot of work because it can control the layout of multiple web pages all at once.

Analogy: If HTML is the blueprint of a house, CSS is the interior decorator. It decides the paint colors of the walls, the type of flooring, the style of the furniture, and how big the windows are. Without CSS, your HTML 'house' would be structurally sound but very bland – just plain text on a white background.

CSS Rules: Selectors, Properties, and Values

A CSS rule set consists of a selector and a declaration block.

  • Selector: Points to the HTML element(s) you want to style (e.g., p for paragraphs, h1 for main headings).
  • Declaration Block: Contains one or more declarations separated by semicolons. Each declaration includes a property name and a value, separated by a colon (property: value;).
p { /* This is the selector, targeting all <p> tags */
    color: blue; /* This is a declaration: property is 'color', value is 'blue' */
    font-family: sans-serif; /* Another declaration */
    font-size: 16px;
}

In this example, all <p> elements on the page will have blue text, use a sans-serif font, and be 16 pixels in size.

How to Include CSS (The Three Ways)

There are three main ways to add CSS to your HTML documents:

  1. Inline CSS: By using the style attribute directly within an HTML element. This is generally discouraged for larger projects because it mixes content and style, making it hard to maintain.
    <p style="color: red; font-size: 20px;">This text is red and large.</p>
  2. Internal CSS: By using a <style> element in the <head> section of an HTML page. This is useful for single pages where you want specific styles.
    <head>
        <style>
            h1 {
                color: green;
                text-align: center;
            }
        </style>
    </head>
  3. External CSS (Most Common & Recommended): By linking to an external .css file using the <link> element in the <head> section. This allows you to apply the same styles to multiple HTML pages, making your website consistent and easy to update.
    <head>
        <link rel="stylesheet" href="styles.css">
    </head>

    Then, in a separate file named styles.css, you would have your CSS rules:

    /* styles.css */
    body {
        background-color: lightblue;
    }
    h2 {
        color: navy;
    }
    

Common CSS Properties

  • color: Sets the text color. (e.g., color: red;)
  • background-color: Sets the background color of an element. (e.g., background-color: lightgray;)
  • font-family: Sets the font for text. (e.g., font-family: 'Times New Roman', serif;)
  • font-size: Sets the size of the text. (e.g., font-size: 18px;)
  • text-align: Aligns the text within an element. (e.g., text-align: center;)
  • width and height: Sets the width and height of an element. (e.g., width: 50%;, height: 200px;)
  • margin and padding: Control the spacing around elements. Margin is outside the border, padding is inside.

Bringing it All Together: HTML and CSS in Harmony

HTML and CSS are two sides of the same coin when it comes to web design. HTML defines the content and its structure, while CSS dictates how that content looks and is presented. They work hand-in-hand to create the beautiful and interactive websites you see every day.

Analogy: Think of it like a play. HTML writes the script and describes the characters and scenes, while CSS designs the costumes, props, and set decorations. Without the script, there's no story; without the design, the story might be hard to follow or not visually engaging. Both are essential for a successful production!

Here's a visual representation of how HTML provides the structure and CSS adds the styling:

A Simple Combined Example:

Let's look at a basic HTML page linked to an external CSS file:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Styled Page</title>
    <link rel="stylesheet" href="styles.css"> <!-- Link to our CSS file -->
</head>
<body>
    <h1>Welcome to My Awesome Page!</h1>
    <p>This paragraph has been styled with CSS.</p>
    <div class="highlight">
        <p>This text is inside a div with a special class.</p>
    </div>
</body>
</html>

styles.css

body {
    font-family: 'Verdana', sans-serif;
    background-color: #e0f2f7;
    color: #333;
    margin: 40px;
}

h1 {
    color: #007bff;
    text-align: center;
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
}

p {
    font-size: 18px;
    line-height: 1.8;
}

.highlight {
    background-color: #fff3cd;
    border: 1px solid #ffeeba;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
}

.highlight p {
    color: #664d03;
    font-weight: bold;
}

If you were to open the index.html file in a web browser, it would display a page with a light blue background, Verdana font, a blue centered heading, and a highlighted section with specific styling, all thanks to the interaction between HTML's structure and CSS's rules.

Conclusion & Next Steps

Congratulations! You've just taken your first major steps into the world of web development. You now understand that HTML is about structuring your web content, and CSS is about styling that content to make it visually appealing. These two languages are the bedrock of almost every website you visit.

To continue your journey, try creating your own simple HTML file, add some headings and paragraphs, and then create a separate CSS file to give them some color, change their font, or center your text. The best way to learn is by doing!

Keep learning, free

Create a free Syllabax account to unlock practice questions and games for this topic.

Visual Learning Enhanced! 🚀

To help you master this topic, we use Advanced Syllabax AI to generate detailed diagrams and visual models.

Note on Visuals: The AI sometimes makes spelling errors in image labels. Please refer to the lesson text for the correct terminology.