HTML Syntax & Structure
Learn the fundamental syntax of HTML — tags, elements, attributes, and how to write proper HTML.
HTML Syntax & Structure
Before writing any HTML, you need to understand the building blocks: tags, elements, and attributes.
HTML Tags
A tag is a keyword surrounded by angle brackets. Most tags come in pairs — an opening tag and a closing tag:
<tagname>Content goes here</tagname>
The closing tag has a forward slash (/) before the tag name.
HTML Elements
An element is the combination of the opening tag, the content, and the closing tag:
<p>This is a paragraph element.</p>
Opening tag: <p>
Content: This is a paragraph element.
Closing tag: </p>
Self-Closing Tags
Some tags don't have content and don't need a closing tag. These are called self-closing (or void) elements:
<br> <!-- Line break -->
<hr> <!-- Horizontal rule -->
<img> <!-- Image -->
<input> <!-- Input field -->
HTML Attributes
Attributes provide additional information about an element. They are always written in the opening tag:
<tagname attribute="value">Content</tagname>
Examples:
<a href="https://notearc.info">Visit NoteArc</a>
<img src="photo.jpg" alt="A beautiful photo">
<p class="intro">Welcome!</p>
Nesting Elements
Elements can be placed inside other elements. This is called nesting:
<div>
<h1>My Title</h1>
<p>My paragraph with a <strong>bold word</strong>.</p>
</div>
Important: always close tags in the correct order. The last tag opened must be closed first.
Comments
Comments are invisible to users but help developers document their code:
<!-- This is a comment. The browser ignores it. -->
Case Sensitivity
HTML tags are not case-sensitive — <P> and <p> both work. However, the convention is to always use lowercase tags.
Key Takeaways
- Tags are keywords wrapped in angle brackets:
<tag> - Most elements have opening and closing tags
- Some elements are self-closing (e.g.,
<br>,<img>) - Attributes add extra information to elements
- Elements can be nested inside each other
- Use lowercase for all tag names