HTML and CSS Beginner Tutorial with Practice Examples

POLYGON INFOTECH JOURNAL

Learn HTML and CSS basics with beginner-friendly examples, page structure, styling, responsive layouts, exercises and common interview questions.

← All Articles

HTML and CSS Beginner Tutorial with Practice Examples

HTML and CSS are the foundations of frontend web development. HTML defines the structure of a webpage, while CSS controls its appearance. Students learning website development should understand both technologies before moving to JavaScript or frontend frameworks.

1. What Is HTML?

HTML stands for HyperText Markup Language. It uses elements to describe headings, paragraphs, links, images, forms and other webpage content.

A basic HTML document contains a document type declaration, an html element, a head section and a body section.

Example:


<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <title>My First Website</title>

</head>

<body>

  <h1>Welcome to My Website</h1>

  <p>I am learning HTML.</p>

</body>

</html>

Save this example as index.html and open it in a web browser.

2. Common HTML Elements

The h1 to h6 elements define headings. The p element creates paragraphs. The a element creates hyperlinks, and the img element displays images.

The ul and ol elements create unordered and ordered lists. The form element groups interactive fields such as input, select and textarea.

Use semantic elements such as header, nav, main, section, article and footer to communicate the purpose of page regions.

3. What Is CSS?

CSS stands for Cascading Style Sheets. It defines colors, spacing, typography, borders, layouts and responsive behavior.

Example:


body {

  font-family: Arial, sans-serif;

  margin: 0;

  background: #f5f7fa;

}


h1 {

  color: #176b55;

  text-align: center;

}


p {

  line-height: 1.6;

}

CSS can be written inside a style element, directly on an HTML element or in an external stylesheet. External stylesheets are generally easier to maintain.

4. Connecting HTML and CSS

Create an index.html file and a style.css file in the same folder.

Add this line inside the HTML head:


<link rel="stylesheet" href="style.css">

The browser will load the stylesheet and apply its matching rules.

5. Understanding CSS Selectors

An element selector targets HTML elements by name. A class selector begins with a period, and an ID selector begins with a hash character.

Example:


.card {

  padding: 20px;

  border-radius: 12px;

}


#main-title {

  font-size: 32px;

}

Classes are useful for reusable components. IDs should identify unique elements.

6. CSS Box Model

Every element has content, padding, border and margin.

Content is the actual text or media. Padding creates space inside the border. Margin creates space outside the border.

A useful rule is:


* {

  box-sizing: border-box;

}

This makes element dimensions easier to manage because declared widths include padding and borders.

7. Building a Simple Card

HTML:


<article class="card">

  <h2>Student Project</h2>

  <p>My first responsive card.</p>

</article>

CSS:


.card {

  max-width: 420px;

  margin: 24px auto;

  padding: 24px;

  border: 1px solid #ddd;

  border-radius: 12px;

  background: white;

}

This exercise introduces reusable styling, spacing and basic layout.

8. Responsive Web Design

Responsive design allows pages to adapt to different screen sizes.

Example:


.container {

  width: min(100% - 32px, 1100px);

  margin-inline: auto;

}


@media (max-width: 600px) {

  h1 {

    font-size: 26px;

  }

}

Use flexible widths, CSS Grid, Flexbox and media queries instead of relying on fixed desktop dimensions.

9. HTML Forms for Beginners

A contact form may contain name, email, phone and message fields.

Each input should have an associated label. Use suitable input types such as email and tel.

Frontend validation improves usability, but real applications must also validate submitted data on the server.

10. Practice Exercises

Exercise 1: Create a personal profile page with a heading, image, introduction and contact links.

Exercise 2: Build a navigation bar with three links.

Exercise 3: Design a product card using padding, borders and a button.

Exercise 4: Create a responsive two-column layout that becomes one column on mobile screens.

Exercise 5: Build a registration form with accessible labels and required fields.

11. Common Beginner Mistakes

Avoid missing closing tags, incorrect file paths and overly specific CSS selectors.

Do not use heading elements only to make text larger. Choose headings based on document structure.

Avoid fixed-width layouts that overflow on mobile devices. Always test keyboard navigation, image alternative text and color contrast.

12. Frequently Asked Questions

Is HTML a programming language?

HTML is a markup language used to structure content. It does not provide general-purpose programming logic.

Can I learn CSS without HTML?

You can study CSS syntax separately, but practical CSS work requires understanding HTML elements and document structure.

Should beginners learn Flexbox or Grid first?

Learn both. Flexbox is especially useful for one-dimensional layouts, while Grid is useful for two-dimensional arrangements.

What should I learn after HTML and CSS?

JavaScript is a natural next step. After learning JavaScript fundamentals, practice DOM manipulation, forms, API requests and small projects.

Conclusion

HTML and CSS provide the foundation for building accessible, responsive websites. The most effective learning approach is to create small pages, inspect the result in a browser and improve each project through practice.

Students can use these skills to build portfolios, college projects and the frontend of larger software applications.

Enterprise Credibility

Why Chhattisgarh Institutions Trust Polygon Infotech

18+ Years

Operating Since 2007

Delivering enterprise software & ERP systems from Ghadi Chowk, Raipur across Chhattisgarh.

Govt. MSME

Recognized Enterprise

Official Udyam-registered software development and technological solutions provider.

100% Secure

Full Data Sovereignty

Zero vendor lock-in. You own your source code and data hosted on private secure clouds or on-premise.

On-Site CG

Direct Engineering Support

Dedicated engineers deployed directly to your factory floor, school, or showroom in Raipur, Bhilai & Bilaspur.