0Pricing
HTML for Kids · Lesson

Writing Clean Code

Learn how to format your HTML for readability.

Writing Clean Code is a free HTML for Kids lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the HTML for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

1

Writing Clean Code

Welcome to the next lesson! Today, we’ll learn how to write clean, readable, and organized HTML code. Clean code makes your pages easier to manage and understand.

Writing Clean Code — illustration 1

2

Why is Clean Code Important?

Clean code helps in:

  • Making your code easier to read and understand.
  • Reducing errors and debugging time.
  • Collaborating with others more effectively.

Let’s learn some tips for writing clean HTML!

3

Use Proper Indentation

Indentation organizes your code and shows the structure of your HTML elements. Each nested element should be indented by a few spaces or a tab.

Example:

Tip: Always use consistent indentation!

<!DOCTYPE html>
<html>
  <head>
    <title>My Page</title>
  </head>
  <body>
    <h1>Welcome</h1>
    <p>This is a paragraph.</p>
  </body>
</html>

4

Close All Tags

Ensure every opening tag has a corresponding closing tag. Forgetting to close tags can cause layout issues.

Example:

Correct:

<p>This is a paragraph.</p>

Incorrect:

<p>This is a paragraph.

5

Use Meaningful Names

When using class or id attributes, give them meaningful names to describe their purpose.

Example:

Tip: Avoid names like div1 or random123.

<p id="welcome-text">Welcome to my website!</p>
<div class="menu">Menu items go here.</div>

6

Add Comments

Comments explain your code and help others (and yourself!) understand it later. Use the <!-- --> syntax for comments.

Example:

Tip: Keep comments short and to the point.

<!-- This is a heading -->
<h1>Welcome to My Page</h1>

<!-- This section contains the navigation menu -->
<div class="menu">
  <a href="#home">Home</a>
  <a href="#about">About</a>
</div>

7

Use Semantic Tags

Semantic tags describe the purpose of the content. For example:

  • <header>: For the top section or header.
  • <article>: For individual articles.
  • <footer>: For the bottom section or footer.

Example:

<header>
  <h1>Welcome to My Blog</h1>
</header>
<article>
  <h2>First Post</h2>
  <p>This is my first blog post.</p>
</article>
<footer>
  <p>© 2024 My Blog</p>
</footer>

8

Organize Your Files

Keep your HTML, CSS, and JavaScript files organized. Use folders like: 

  • images: For all your images. 
  • css: For your CSS files. 
  • js: For your JavaScript files.

Example folder structure:

project/
├── index.html
├── css/
│   └── styles.css
├── js/
│   └── script.js
└── images/
    └── logo.png

9

10

Great Job!

Congratulations! You’ve learned how to write clean and organized HTML code. Clean code makes your projects easier to maintain and share. In the next lesson, we’ll explore accessibility basics to ensure your web pages are user-friendly for everyone. Get ready to make your pages inclusive!

Writing Clean Code — illustration 10

Frequently asked questions

Is the “Writing Clean Code” lesson free?

Yes — the full text of “Writing Clean Code” is free to read here on the web, and the HTML for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the HTML for Kids course, upgrade to CoddyKit PRO.

What will I learn in “Writing Clean Code”?

Learn how to format your HTML for readability. You practise HTML for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start HTML for Kids?

No prior experience is required. HTML for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Writing Clean Code” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this HTML for Kids lesson?

Yes. Every HTML for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Writing Clean Code
  2. Accessibility Basics
  3. Validating Your HTML
  4. HTML Comments
← Back to HTML for Kids