⬅ Back

Tags and Attributes

Idea

Websites are like cars. People use them every day, but they don’t know how they work inside. Developers understand what is “under the hood”.

Tags

A tag is a basic building block of HTML. Every page is made of tags. A tag can represent a heading, paragraph, list, image, or button.

Example:

<tag>Content</tag>

Opening tag = start Closing tag = end (with /)

<section>Section</section>
<p>Paragraph</p>
<a>Link</a>
<button>Button</button>

HTML element = tag + content

Paragraph Tag

The <p> tag is used for text paragraphs. It starts on a new line and has spacing.

<p>This is a paragraph</p>

Heading Tag

The <h1> tag is the main heading of a page. It is usually used only once.

<h1>Sweet cheese pancakes</h1>

Comments

Comments are used to explain code or hide parts of it. They are not visible on the page.

<!-- This is a comment -->

Attributes

Attributes give extra information to tags. They are written inside the opening tag.

<a href="https://google.com">Link</a>

Rules:

Links

The <a> tag creates links.

<a href="https://google.com">Google</a>

To open in a new tab:

<a href="https://google.com" target="_blank">Google</a>

Images

The <img> tag is used to show images. It is a single tag (no closing tag).

<img src="image.jpg" alt="description">

Important attributes:

Paired and Single Tags

Paired tags:

Single tags:

Lists

Unordered list:

<ul>
  <li>Item 1</li>
</ul>

Ordered list:

<ol>
  <li>Step 1</li>
</ol>

Headings Hierarchy

Headings go from <h1> to <h6>. They show importance and structure.

Semantic HTML

Semantic HTML means using tags by their meaning.

Code Style Rules

⬅ Back