Introduction to HTML and CSS
- Get link
- X
- Other Apps
Introduction to HTML and CSS
1. What Are HTML and CSS?
Every website you visit—whether it’s a blog, an online store, or a social media platform—is built on a foundation of HTML and CSS.
These two technologies form the backbone of the modern web.
-
HTML (HyperText Markup Language) defines the structure of a web page.
-
CSS (Cascading Style Sheets) controls the appearance and layout of that structure.
A simple way to understand their relationship is to think of HTML as the skeleton of a building and CSS as the interior design and paint that make it visually appealing.
Understanding HTML and CSS is the first and most important step for anyone who wants to become a web developer, create personal websites, or understand how the internet really works.
2. Understanding HTML: The Structure of the Web
HTML uses elements (also called tags) to describe different parts of a web page.
Each element tells the browser what kind of content it represents.
2.1 Basic HTML Document Structure
Every HTML page follows a standard structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First Web Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first HTML page.</p>
</body>
</html>
Explanation:
-
<!DOCTYPE html>tells the browser this is an HTML5 document. -
<html>is the root element. -
<head>contains metadata (not visible on the page). -
<body>contains all visible content.
3. Common HTML Elements You Should Know
3.1 Headings and Paragraphs
HTML provides six levels of headings:
<h1>Main Title</h1>
<h2>Section Title</h2>
<h3>Subsection</h3>
Paragraphs are created using the <p> tag:
<p>This is a paragraph of text.</p>
3.2 Links and Images
Links allow users to navigate between pages:
<a href="https://example.com">Visit Example</a>
Images add visual content:
<img src="image.jpg" alt="A descriptive text">
The alt attribute is important for accessibility.
3.3 Lists
HTML supports ordered and unordered lists:
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<ol>
<li>Learn HTML</li>
<li>Learn CSS</li>
<li>Build Projects</li>
</ol>
3.4 Semantic HTML
Semantic elements describe their meaning clearly:
<header>
<h1>My Blog</h1>
</header>
<main>
<article>
<h2>First Post</h2>
<p>This is an article.</p>
</article>
</main>
<footer>
<p>© 2025 My Blog</p>
</footer>
Using semantic HTML improves accessibility and code readability.
4. Introduction to CSS: Styling the Web
CSS controls how HTML elements look on the screen.
It defines colors, fonts, spacing, layouts, and animations.
4.1 How CSS Works
CSS rules consist of:
-
A selector
-
A property
-
A value
p {
color: blue;
font-size: 16px;
}
This rule applies to all <p> elements.
4.2 Ways to Add CSS
Inline CSS
<p style="color: red;">Red text</p>
Internal CSS
<style>
p { color: green; }
</style>
External CSS (Recommended)
<link rel="stylesheet" href="styles.css">
p {
color: black;
}
External CSS keeps code clean and maintainable.
5. Core CSS Concepts
5.1 Colors and Fonts
body {
background-color: #f4f4f4;
font-family: Arial, sans-serif;
}
CSS supports named colors, HEX, RGB, and HSL formats.
5.2 Box Model
Every element is a box made of:
-
Content
-
Padding
-
Border
-
Margin
div {
width: 300px;
padding: 20px;
border: 2px solid black;
margin: 10px;
}
Understanding the box model is essential for layout design.
5.3 Layout with Flexbox
Flexbox is a modern layout system:
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
<div class="container">
<div>Item 1</div>
<div>Item 2</div>
</div>
Flexbox makes responsive layouts easier than older methods.
6. A Simple HTML + CSS Example
6.1 HTML File
<!DOCTYPE html>
<html>
<head>
<title>Simple Website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<main>
<p>This website is built using HTML and CSS.</p>
<button>Click Me</button>
</main>
</body>
</html>
6.2 CSS File
body {
font-family: Arial, sans-serif;
background-color: #ffffff;
text-align: center;
}
header {
background-color: #333;
color: white;
padding: 20px;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
}
This example demonstrates structure (HTML) and styling (CSS) working together.
7. Why HTML and CSS Matter
HTML and CSS are:
-
Essential for web development
-
Beginner-friendly
-
Required knowledge for frameworks like React or Vue
Even backend developers benefit from understanding these technologies.
8. What to Learn Next
After mastering HTML and CSS, consider learning:
-
Responsive Design
-
CSS Grid
-
JavaScript basics
-
Web accessibility (ARIA)
-
Browser rendering performance
9. Conclusion
HTML and CSS are the building blocks of the web.
HTML gives structure and meaning to content, while CSS transforms that structure into visually appealing, user-friendly designs.
Learning these technologies opens the door to modern web development and provides a solid foundation for more advanced tools and frameworks.
Whether you want to build a personal blog, a portfolio, or a professional website, mastering HTML and CSS is the first step toward creating your presence on the web.
