:strip_exif():quality(75)/medias/7556/ec5977c9fe13f44d4bd9e09a984a87d5.jpg)
Want to Build Websites? Learn HTML & CSS!
So, you want to build websites? Awesome! Learning HTML and CSS is the first step. Think of it like learning the alphabet for web pages. This guide will get you started.
What's HTML?
HTML, or HyperText Markup Language, is the foundation of every website. It structures the content—headings, paragraphs, images, you name it. It's the website's skeleton. HTML uses tags, like this: <p>This is a paragraph</p>
. See those angle brackets? Those are the tags. They always come in pairs.
And CSS?
CSS, or Cascading Style Sheets, is all about styling. HTML builds the structure; CSS makes it look good. Think of it as the website's clothing and makeup. Keeping HTML and CSS separate makes your code easier to update.
Setting Up: It's Easy!
You just need a text editor and a web browser. That's it! Here are some popular text editors:
- VS Code (Visual Studio Code): Free, powerful, and super popular.
- Sublime Text: Lightweight and speedy.
- Atom: Free, open-source, and very customizable.
- Notepad++ (Windows only): Simple and free—great for beginners.
Any modern browser (Chrome, Firefox, Safari, Edge) works fine.
Basic HTML Structure: Let's Break It Down
Every HTML page follows this basic structure:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<p>This is a paragraph.</p>
</body>
</html>
Here's what it all means:
<!DOCTYPE html>
: Tells the browser it's an HTML5 doc.
<html>
: The main container—everything goes inside.
<head>
: Holds info not shown on the page, like the title (what you see in your browser tab).
<body>
: This is where the visible content goes.
Important HTML Elements
Here are some you'll use all the time:
<h1>
to <h6>
: Headings (<h1>
is biggest, <h6>
is smallest).
<p>
: Paragraphs.
<a href="url">
: Links! (href
is where the link goes).
<img src="image.jpg" alt="Description">
: Images! (src
is the image file, alt
describes the image for screen readers).
<ul>
and <ol>
: Unordered (bulleted) and ordered (numbered) lists.
<li>
: List items (goes inside <ul>
and <ol>
).
<div>
and <span>
: Containers for grouping and styling. <div>
is for block elements, <span>
for inline elements.
Let's Add Some Style with CSS!
Now for the fun part—making things look pretty! You can add CSS directly into your HTML, link to a separate CSS file (best for bigger projects!), or use inline styles (generally avoid this for better organization).
Adding CSS Directly (Embedding)
<style>
body {
background-color: #f0f0f0;
font-family: sans-serif;
}
p {
color: #333;
}
</style>
Linking to an External CSS File
This is better for larger projects. Make a file (like styles.css
), then link it like this:
<link rel="stylesheet" href="styles.css">
CSS Selectors and Properties
CSS uses selectors to target HTML elements and properties to change their styles.
body { background-color: blue; }
: Makes the background blue.
h1 { color: red; font-size: 2em; }
: Makes all <h1>
headings red and twice the normal size.
p.intro { text-align: center; }
: Centers text in paragraphs with the class "intro".
Practice Makes Perfect!
The best way to learn is by doing! Start small—create a simple page with headings, paragraphs, and images. Then, build from there. Here are some great resources:
- freeCodeCamp: Interactive challenges and projects.
- Codecademy: Interactive courses.
- MDN Web Docs (Mozilla): Comprehensive documentation.
- W3Schools: Tutorials and references.
Be patient! Learning takes time. But it's so rewarding to build your own websites!
Going Further: Advanced Stuff
Once you've got the basics down, try these:
- Responsive Web Design: Websites that look great on all devices.
- CSS Frameworks (Bootstrap, Tailwind): Pre-built styles to speed up development.
- CSS Preprocessors (Sass, Less): Make writing CSS easier.
- JavaScript: Add interactivity!
- Semantic HTML: Use HTML elements that clearly describe the content.
You'll be building amazing websites in no time!