Every website begins with a structure that organizes its content and a visual design that makes information easy to read and interact with.
HTML and CSS are two fundamental technologies used to create that experience. HTML defines the structure of a web page, while CSS controls its appearance, spacing, colors and layout.
Understanding how these technologies work together is an important first step for anyone interested in web development.
In this guide, we will explore the basics of HTML and CSS and build a simple responsive website layout.
1. Understanding HTML
HTML stands for HyperText Markup Language. It describes the structure and meaning of content displayed in a browser.
HTML uses elements, commonly written with opening and closing tags, to organize information.
For example:
<h1>Welcome to My Website</h1>
<p>This is my first web page.</p>
<a href="https://example.com">Visit Website</a>
This example contains three common HTML elements:
<h1>creates a main heading.<p>creates a paragraph.<a>creates a hyperlink.
HTML also provides elements for images, lists, tables, forms and many other types of content.
2. Creating a Basic HTML Document
A complete HTML page follows a standard document structure.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Website</title>
</head>
<body>
<header>
<h1>My Website</h1>
</header>
<main>
<p>Welcome to my first web page.</p>
</main>
<footer>
<p>Copyright 2026</p>
</footer>
</body>
</html>
The head section contains document information and metadata.
The body section contains the content visitors see.
Elements such as header, main and footer provide semantic meaning and help organize a page into understandable sections.
3. What Is CSS?
CSS stands for Cascading Style Sheets.
It controls how HTML elements appear in a browser.
CSS can define:
- Text colors and font sizes.
- Background colors and images.
- Margins and padding.
- Borders and rounded corners.
- Layouts and alignment.
- Responsive behavior.
A simple CSS example:
body {
font-family: Arial, sans-serif;
background-color: #f5f2ec;
color: #242522;
margin: 0;
}
h1 {
font-size: 36px;
color: #c86b43;
}
p {
line-height: 1.7;
}
CSS separates visual presentation from document structure, making websites easier to maintain and update.
4. Understanding the CSS Box Model
One of the most important CSS concepts is the box model.
Every HTML element is treated as a rectangular box consisting of:
- Content: The actual text, image or other content.
- Padding: Space between the content and its border.
- Border: The boundary around the element.
- Margin: Space outside the border.
For example:
.card {
width: 300px;
padding: 20px;
border: 1px solid #dddddd;
margin: 16px;
box-sizing: border-box;
}
Using box-sizing: border-box makes width calculations easier because padding and borders are included in the declared width.
Understanding the box model helps prevent unexpected spacing and layout problems.
5. Building Layouts with Flexbox and Grid
Modern websites often use CSS Flexbox and Grid to organize content.
Flexbox
Flexbox is useful for arranging elements along a row or column.
.navigation {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
}
This example creates a horizontal layout with space between its items.
CSS Grid
Grid is useful for building structured two-dimensional layouts.
.article-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 24px;
}
This creates three equal-width columns with consistent spacing.
Both systems are widely used when building modern websites.
6. Making Websites Responsive
A responsive website adapts its layout to different screen sizes.
A desktop page might display three article cards in one row, while a mobile device may display only one card per row.
CSS media queries make this possible:
.article-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 24px;
}
@media (max-width: 768px) {
.article-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 480px) {
.article-grid {
grid-template-columns: 1fr;
}
}
This approach changes the layout based on the available screen width.
Responsive design should also consider readable typography, touch-friendly controls and images that fit their containers.
7. Best Practices for Clean HTML and CSS
Writing organized code makes websites easier to maintain and improves collaboration.
Consider these practices:
- Use semantic HTML elements.
- Keep CSS rules organized.
- Use consistent spacing and typography.
- Give images descriptive alternative text.
- Avoid unnecessary HTML nesting.
- Test pages at different screen sizes.
- Reuse styles for repeated components.
Accessibility should also be considered from the beginning. Clear headings, meaningful links and properly labeled forms make websites easier for more people to use.
Conclusion
HTML and CSS form the foundation of front-end web development.
HTML organizes the content, while CSS creates the visual presentation and responsive layouts that make websites work across different devices.
By practicing document structure, styling, the box model, Flexbox and Grid, you can begin creating your own web pages with confidence.
Explore more HTML, CSS and web development tutorials with Skillora Code and continue building your technical skills.
