Core Concepts
🏷️ HTML Elements
HTML elements are the building blocks of web pages. Each element has a tag that defines its purpose.
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>Main Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
🎨 CSS Styling
CSS is used to style HTML elements and make them visually appealing.
color: #264de4;
font-size: 2em;
text-align: center;
}
.button {
background-color: #4ecdc4;
padding: 10px 20px;
border-radius: 5px;
}
📐 Layout Techniques
Modern CSS provides powerful layout systems like Flexbox and Grid.
.container {
display: flex;
justify-content: space-between;
}
/* Grid example */
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
Flexbox Layout Demo
Flexbox allows for flexible alignment and distribution of elements within a container.
Grid Layout Demo
CSS Grid enables two-dimensional layout control for rows and columns.
Responsive Design
Use media queries to create layouts that adapt to different screen sizes.
.container {
padding: 10px;
}
@media (min-width: 768px) {
.container {
max-width: 768px;
margin: 0 auto;
}
}
@media (min-width: 1024px) {
.container {
max-width: 1200px;
}
}
Try resizing your browser window to see how this section adapts!
This responsive design adjusts its padding and maximum width based on the screen size, demonstrating the principles of mobile-first design.
Complete Example
Here's a complete HTML document showing how HTML and CSS work together:
<html>
<head>
<title>Sample Page</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
header {
background-color: #264de4;
color: white;
padding: 1rem;
text-align: center;
}
main {
margin: 20px 0;
}
footer {
text-align: center;
color: #666;
margin-top: 20px;
}
</style>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
</header>
<main>
<p>This is the main content area.</p>
<p>HTML structures the content and CSS styles it.</p>
</main>
<footer>
<p>Copyright © 2023</p>
</footer>
</body>
</html>