Everything you need as a full stack developer

HTML and CSS Fundamentals

- Posted in Junior Developer by

TL;DR HTML and CSS are the fundamental building blocks of the web, forming the backbone of every website, application, and online experience. HTML provides structure and content, using tags to define elements such as headings, paragraphs, and images. CSS enhances visual presentation with rules that target specific HTML elements, defining properties and values for layout, color, and more. By combining these technologies, developers can create engaging, responsive, and visually appealing web experiences.

HTML and CSS Fundamentals: Building the Web from Scratch

As a full-stack developer, it's essential to have a solid grasp of the fundamental building blocks of the web: HTML and CSS. These two technologies form the backbone of every website, application, and online experience. In this article, we'll dive into the basics of HTML and CSS, exploring what they are, how they work together, and creating some "Hello World" examples to get you started.

What is HTML?

HTML (Hypertext Markup Language) is a standard markup language used to create web pages. It's the structure and content layer of your website, defining the different elements that make up a web page, such as headings, paragraphs, images, links, forms, tables, and more.

HTML consists of a series of elements, represented by tags (<>). These tags are surrounded by angle brackets and usually come in pairs, with the opening tag preceding the content and the closing tag following it. The basic structure of an HTML document includes:

  • <!DOCTYPE html>: The document type declaration
  • <html>: The root element of the HTML document
  • <head>: Contains metadata about the document, such as the title, styles, and scripts
  • <body>: The content of the HTML document

Basic HTML Elements

Let's create a simple "Hello World" HTML page to demonstrate some basic elements:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello World!</title>
  </head>
  <body>
    <h1>Hello, World!</h1>
    <p>This is a paragraph of text.</p>
  </body>
</html>

In this example:

  • <h1> defines a heading element with the text "Hello, World!"
  • <p> defines a paragraph element with some sample text

What is CSS?

CSS (Cascading Style Sheets) is a styling language used to control the layout and visual aspects of web pages written in HTML or XML. It's responsible for making your website look visually appealing, responsive, and engaging.

CSS consists of rules, known as styles, which are applied to specific HTML elements using selectors. A CSS rule typically includes:

  • Selector: Targets the HTML element(s) to apply the style
  • Property: Defines the aspect of the element to be styled (e.g., color, font-size)
  • Value: Specifies the value for the property

Basic CSS Styles

Let's add some basic styles to our "Hello World" HTML page:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello World!</title>
    <style>
      body {
        background-color: #f2f2f2;
      }
      h1 {
        color: blue;
        font-size: 36px;
      }
    </style>
  </head>
  <body>
    <h1>Hello, World!</h1>
    <p>This is a paragraph of text.</p>
  </body>
</html>

In this example:

  • The body element has its background color set to a light gray (#f2f2f2)
  • The h1 element has its text color set to blue and font size set to 36 pixels

How HTML and CSS Work Together

HTML provides the structure and content, while CSS enhances the visual presentation. When a web browser loads an HTML document, it reads the HTML elements and applies the corresponding CSS styles.

To illustrate this, let's create a simple example that demonstrates how HTML and CSS work together:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML and CSS Together</title>
    <style>
      .container {
        width: 80%;
        margin: 40px auto;
        background-color: #fff;
        padding: 20px;
        border: 1px solid #ddd;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
      }
    </style>
  </head>
  <body>
    <div class="container">
      <h2>Welcome to our website!</h2>
      <p>This is a sample paragraph of text.</p>
    </div>
  </body>
</html>

In this example:

  • The HTML div element has a class attribute set to "container", which targets the CSS rule
  • The CSS rule defines various styles for the .container class, such as width, margin, background color, padding, border, and box shadow

As you can see, HTML provides the structure and content, while CSS enhances the visual presentation. By combining these two technologies, you can create engaging, responsive, and visually appealing web experiences.

This article has covered the basics of HTML and CSS, providing a solid foundation for further learning and exploration. In future articles, we'll dive deeper into advanced topics, such as semantic HTML, CSS preprocessors, and modern layout techniques. Stay tuned!

Key Use Case

Create a personal website to showcase your skills and experience. Start by building the structure of the website using basic HTML elements such as headings, paragraphs, images, and links. Then, add styles to enhance the visual presentation using CSS rules, targeting specific HTML elements with selectors and defining properties and values.

Finally

With a solid grasp of HTML and CSS fundamentals, you'll be well-equipped to tackle more advanced topics and create complex web experiences. As you continue to learn and grow as a developer, remember that these basics form the foundation upon which all other web technologies are built. By mastering HTML and CSS, you'll unlock the full potential of the web and be able to bring your most ambitious projects to life.

Recommended Books

• "HTML and CSS: Design and Build Websites" by Jon Duckett • "CSS Pocket Reference" by Eric A. Meyer • "HTML5 and CSS3 for Web Designers" by Ben Frain

Fullstackist aims to provide immersive and explanatory content for full stack developers Fullstackist aims to provide immersive and explanatory content for full stack developers
Backend Developer 103 Being a Fullstack Developer 107 CSS 109 Devops and Cloud 70 Flask 108 Frontend Developer 357 Fullstack Testing 99 HTML 171 Intermediate Developer 105 JavaScript 206 Junior Developer 124 Laravel 221 React 110 Senior Lead Developer 124 VCS Version Control Systems 99 Vue.js 108

Recent Posts

Web development learning resources and communities for beginners...

TL;DR As a beginner in web development, navigating the vast expanse of online resources can be daunting but with the right resources and communities by your side, you'll be well-equipped to tackle any challenge that comes your way. Unlocking the World of Web Development: Essential Learning Resources and Communities for Beginners As a beginner in web development, navigating the vast expanse of online resources can be daunting. With so many tutorials, courses, and communities vying for attention, it's easy to get lost in the sea of information. But fear not! In this article, we'll guide you through the most valuable learning resources and communities that will help you kickstart your web development journey.

Read more

Understanding component-based architecture for UI development...

Component-based architecture breaks down complex user interfaces into smaller, reusable components, improving modularity, reusability, maintenance, and collaboration in UI development. It allows developers to build, maintain, and update large-scale applications more efficiently by creating independent units that can be used across multiple pages or even applications.

Read more

What is a Single Page Application (SPA) vs a multi-page site?...

Single Page Applications (SPAs) load a single HTML file initially, handling navigation and interactions dynamically with JavaScript, while Multi-Page Sites (MPS) load multiple pages in sequence from the server. SPAs are often preferred for complex applications requiring dynamic updates and real-time data exchange, but MPS may be suitable for simple websites with minimal user interactions.

Read more