HTML and CSS - Comprehensive Guide
HTML and CSS - Comprehensive Guide
1
Question 3: 8
Best Practices 8
HTML (HyperText Markup Language) and CSS (Cascading Style Sheets) are the foundation of
web development. HTML provides the structure of a webpage, while CSS styles and layouts the
content. This guide will teach you the basics of HTML and CSS, with examples, exercises, and
quizzes to reinforce learning.
1. Introduction to HTML
HTML is the backbone of any webpage, defining its structure with elements (tags).
<a> Hyperlink.
<img> Image.
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis
2
<table> Table.
2. Introduction to CSS
CSS styles the structure provided by HTML. It defines colors, layouts, fonts, and much more.
Inline CSS:
Internal CSS:
<head>
<style>
body {
background-color: #f0f0f0;
}
h1 {
color: green;
}
</style>
</head>
External CSS:
<head>
<link rel="stylesheet" href="styles.css">
</head>
styles.css:
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis
3
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
h1 {
color: navy;
}
3. Box Model
Example:
<div style="width: 200px; padding: 10px; border: 2px solid black;
margin: 20px;">
Box Model Example
</div>
4. CSS Selectors
Common Selectors:
Selector Example Description
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis
4
Descendan div p Selects <p> inside <div>.
t
Example:
<div class="container" id="main">
<p class="text">This is a paragraph.</p>
</div>
CSS:
#main {
background-color: lightgray;
}
.text {
color: blue;
font-size: 18px;
}
5. Responsive Design
Detailed Examples
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis
5
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Simple Webpage</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f9f9f9;
}
header {
background-color: #333;
color: white;
padding: 10px 0;
text-align: center;
}
main {
padding: 20px;
}
footer {
background-color: #333;
color: white;
text-align: center;
padding: 10px 0;
}
</style>
</head>
<body>
<header>
<h1>Welcome to My Webpage</h1>
</header>
<main>
<h2>About Me</h2>
<p>This is a simple webpage created using HTML and CSS.</p>
</main>
<footer>
<p>© 2024 My Website</p>
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis
6
</footer>
</body>
</html>
Exercises
Solution:
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis
7
Exercise 3: Responsive Design
● Add a media query to change the background color for screens smaller than 600px.
Multiple-Choice Questions
Question 1:
1. Paragraph
2. Picture
3. Page
4. Placeholder
Answer: 1. Paragraph
Question 2:
1. color
2. background-color
3. font-color
4. text-background
Answer: 2. background-color
Question 3:
1. To add animations.
2. To create media queries for responsive design.
3. To import external CSS files.
4. To style media elements like videos.
Best Practices
1. Use Semantic HTML: Use tags like <header>, <main>, <footer> for better
accessibility and SEO.
2. Keep CSS Organized: Use external stylesheets for maintainable code.
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis
8
3. Responsive Design: Test on multiple devices and use media queries.
4. Consistent Styling: Use CSS variables to maintain consistent colors and spacing.
Learn more HTML, CSS, JavaScript Web Development at https://basescripts.com/ Laurence Svekis