HTML (HyperText Markup Language) is the foundation of any web page. Learn the essential structure of an HTML document and how to create basic elements.
HTML documents have a standard structure that all browsers recognize:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="UTF-8">
</head>
<body>
<!-- Your visible content goes here -->
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Understanding this structure is crucial:
CSS (Cascading Style Sheets) brings your HTML to life with colors, layout, and design elements.
There are three ways to include CSS in your HTML documents:
Inline CSS is applied directly to HTML elements using the style
attribute:
<p style="color: blue; font-size: 18px;">This is a blue paragraph with 18px font size.</p>
While convenient for small changes, inline styles can become hard to manage for larger projects.
Internal CSS is defined within the <style>
tag in the document's <head>
section:
<head>
<style>
p {
color: blue;
font-size: 18px;
}
.highlight {
background-color: yellow;
}
</style>
</head>
This method is good for styling a single page.
External CSS is stored in a separate .css file and linked to the HTML document:
<head>
<link rel="stylesheet" href="styles.css">
</head>
This is the preferred method for larger websites as it keeps your HTML and CSS separate, making maintenance easier.
Forms allow users to interact with your website by submitting data.
Forms collect user input through various form controls:
<form action="/submit-form" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4"></textarea>
<button type="submit">Submit</button>
</form>
Tip: Always use the <label>
element with form controls to improve accessibility. The for
attribute of the label should match the id
of the form control.
Learn how to use CSS to create responsive layouts and position elements on your page.
Every HTML element is a box with content, padding, border, and margin:
.box {
width: 300px;
padding: 20px;
border: 2px solid #ff5722;
margin: 30px;
}
Understanding the box model is essential for controlling layout and spacing.
Create a simple HTML page with a heading, paragraph, and an image. Then style it using CSS to change colors, font sizes, and add some margins and padding. This hands-on practice will reinforce what you've learned in this module.
Remember to check your work in a browser to see how different CSS properties affect your page's appearance!