Introduction to HTML and CSS: Understanding the Building Blocks of Web Pages

HTML provides the structure of web pages, while CSS controls the presentation and layout. Together, they form the foundation for web development.

Share on Linkedin Share on WhatsApp

Estimated reading time: 5 minutes

Article image Introduction to HTML and CSS: Understanding the Building Blocks of Web Pages

Introduction

HTML (HyperText Markup Language) and CSS (Cascading Style Sheets) are the foundational technologies for creating web pages. HTML provides the structure of the page, while CSS is used to control the presentation, formatting, and layout. Understanding these two technologies is essential for anyone interested in web development.

HTML: The Structure of Web Pages

HTML is the standard markup language for creating web pages. It consists of a series of elements that you use to enclose different parts of the content to make it appear or act a certain way. HTML elements are represented by tags, which can be:

  • Opening Tag: Marks the beginning of an element (e.g., <p> for a paragraph).
  • Closing Tag: Marks the end of an element (e.g., </p>).
  • Self-Closing Tag: Tags that don’t need a closing tag (e.g., <img> for images).

Here’s an example of a simple HTML document:

<!DOCTYPE html>
<html>
<head>
    <title>My First Web Page</title>
</head>
<body>
    <h1>Welcome to My Web Page</h1>
    <p>This is a paragraph of text.</p>
    <img src="image.jpg" alt="A descriptive text for the image">
</body>
</html>

In this example:

  • <!DOCTYPE html> declares the document type.
  • <html> is the root element.
  • <head> contains meta-information about the HTML document.
  • <title> sets the title of the web page.
  • <body> contains the content of the web page.
  • <h1> represents a top-level heading.
  • <p> represents a paragraph.
  • <img> is used to embed an image.

CSS: Styling Web Pages

CSS is used to style and layout web pages. It can control the color, font, size, spacing, and positioning of elements on a page. CSS can be added to HTML documents in three ways:

  1. Inline CSS: Using the style attribute inside HTML elements.
  2. Internal CSS: Using a <style> element inside the <head> section.
  3. External CSS: Linking to an external CSS file using the <link> element.

Here’s an example of each method:

Inline CSS:

<p style="color: blue; font-size: 20px;">This is a styled paragraph.</p>

Internal CSS:

<!DOCTYPE html>
<html>
<head>
    <style>
        p {
            color: blue;
            font-size: 20px;
        }
    </style>
</head>
<body>
    <p>This is a styled paragraph.</p>
</body>
</html>

External CSS:

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
    <p>This is a styled paragraph.</p>
</body>
</html>

styles.css:

p {
    color: blue;
    font-size: 20px;
}

Combining HTML and CSS

By combining HTML and CSS, you can create visually appealing and well-structured web pages. Here’s a more complete example:

<!DOCTYPE html>
<html>
<head>
    <title>My Styled Web Page</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
    <h1>Welcome to My Web Page</h1>
    <p>This is a paragraph of text.</p>
    <img src="image.jpg" alt="A descriptive text for the image">
</body>
</html>

styles.css:

body {
    font-family: Arial, sans-serif;
    margin: 20px;
}

h1 {
    color: green;
    text-align: center;
}

p {
    color: blue;
    font-size: 18px;
}

img {
    display: block;
    margin: 0 auto;
    width: 300px;
}

In this example, the CSS file styles the entire document, making the web page more attractive and easier to read.

Conclusion

HTML and CSS are the fundamental technologies for building web pages. HTML provides the structure, while CSS handles the presentation and layout. By mastering these two technologies, you can create beautiful, functional websites. Practice is key, so start experimenting with your own HTML and CSS code to develop your web development skills.

Understanding AWS Web Hosting: Empowering Modern Applications in the Cloud

Discover how AWS enables secure, scalable, and flexible web hosting for modern applications, from personal sites to enterprise systems.

AWS for Beginners: Essential Concepts and First Steps in Cloud Computing

Learn AWS essentials: from EC2 to S3, get started with cloud computing through practical steps, tools, and tips for beginners.

Understanding AngularJS Directives: Enhancing Web Application Functionality

Learn how AngularJS directives enhance UI, create custom behaviors, and streamline your web development with reusable and powerful components.

Mastering AngularJS Services: Streamlining Data and Logic in Web Applications

Learn how AngularJS services help organize logic, manage data, and build scalable apps with clean, reusable, and testable code.

Getting Started with AngularJS: Powerful Front-End Web Development

Learn AngularJS essentials, its architecture, and how to build dynamic single-page apps with features like data binding, MVC, and reusable components.

AngularJS in Modern Web Applications: Architecture, Components, and Best Practices

Explore AngularJS architecture, components, and best practices to build scalable, maintainable single-page applications with modular design and efficient routing.

Mastering Android UI: Best Practices for Creating Intuitive Mobile Interfaces

Create intuitive Android UIs with Material Design, Jetpack Compose, accessibility, and responsive layouts for seamless user experiences across all devices.

Integrating Cloud Services in Android App Development: Best Practices and Tools

Boost your Android apps with cloud services for real-time sync, scalability, and better UX using Firebase, GCP, AWS, and best development practices.

+ 9 million
students

Free and Valid
Certificate

60 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video and ebooks