Introduction to HTML & CSS
HTML (HyperText Markup Language) is the standard markup language for creating web pages. CSS (Cascading Style Sheets) is used to style and layout web pages. Together, they form the foundation of web development.
Key Features
- HTML structures content on the web
- CSS styles and layouts web pages
- Separation of content and presentation
- Responsive design with media queries
- Supports multimedia (images, audio, video)
- Semantic elements for accessibility
Basic Structure
An HTML document has a standard structure:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Page Title</title>
</head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>
Tags & Attributes
HTML uses tags to mark up content. Attributes provide additional information about elements.
<a href="https://example.com" target="_blank">Visit Example</a>
<h1>...</h1>
to<h6>...</h6>
: Headings<p>
: Paragraph<a>
: Anchor (link)<img>
: Image<div>
,<span>
: Containers
Head & Body
The <head>
contains meta-information, links to CSS, and scripts. The <body>
contains the visible content.
<head>
<meta charset="UTF-8">
<title>My Website</title>
<link rel="stylesheet" href="style.css">
</head>
Lists & Tables
HTML supports ordered, unordered lists, and tables for tabular data.
<ul><li>Item 1</li><li>Item 2</li></ul>
<ol><li>First</li><li>Second</li></ol>
<table><tr><th>Name</th><th>Age</th></tr><tr><td>Alice</td><td>24</td></tr></table>
Forms
Forms collect user input. Common elements: <input>
, <textarea>
, <select>
, <button>
.
<form action="/submit" method="post">
<input type="text" name="username">
<input type="password" name="password">
<button type="submit">Login</button>
</form>
Redirections & Reloads
Redirection can be done using meta tags or JavaScript.
<meta http-equiv="refresh" content="5;url=https://example.com">
window.location.href = "https://example.com";
Reload the page with:
location.reload();
Div, Span, Class, Id
<div>
and <span>
are generic containers. Use class
and id
attributes for styling and scripting.
<div id="header" class="main-header">Header Content</div>
<span class="highlight">Important</span>
CSS, JS & Assets Link
Link CSS and JS files in the <head>
or before </body>
:
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
Use <img>
for images and <video>
or <audio>
for media.
Other Features
- Semantic HTML:
<header>
,<footer>
,<nav>
,<main>
,<section>
- Responsive design with
@media
queries - Accessibility with
alt
attributes and ARIA roles - Favicons and meta tags for SEO