1.HTML Attributes:
- HTML attributes provide extra information about an element.
- They always appear inside the opening tag.
Example:
<img src="photo.jpg" alt="profile picture">
Common HTML Attributes
** 1. id:**
Gives a unique name to an element.
<p id="para1">Hello</p>
2. Class:
Assigns a reusable class for styling or JS.
<p class="text-red">Hello</p>
3. Style:
Adds inline CSS.
<p style="color:blue;">Hello</p>
4. Src:
Used in images, audio, video.
<img src="image.jpg">
5. Href:
Used in links.
<a href="https://example.com">Click</a>
6. Alt:
Alternative text for images.
<img src="img.png" alt="logo">
7. Title:
Shows a tooltip on hover.
<p title="This is a tooltip">Hover me</p>
8. Placeholder
Shows hint text in input fields.
<input type="text" placeholder="Enter name">
9. Value:
Sets the default value of input.
<input type="text" value="John">
10. Disabled:
Disables buttons/inputs.
<button disabled>Submit</button>
2.Semantic HTML:
Semantic HTML means using tags that describe the meaning and purpose of the content, not just the layout.
These tags clearly tell the browser, search engines, and screen readers what each part of the page represents.
Why Semantic HTML Is Important:
Makes pages easier to understand
Improves SEO (search engines read structure better)
Helps screen readers and accessibility tools
Makes code cleaner and easier to maintain
Common Semantic Tags:
1.<header>:
Top section of a page or section.
2. <nav>:
Navigation links.
3.<main>:
Main content of the page.
4. <section>:
Groups related content.
5.<article>:
Independent content like blog posts or news items.
6.<aside>:
Sidebar or extra info.
7. <footer>:
Bottom section with copyright, links, etc.
8. <figure> and <figcaption>:
Images with captions.
Example:
<header>
<h1>My Blog</h1>
</header>
<article>
<h2>Post Title</h2>
<p>This is the content of the blog post.</p>
</article>
<footer>
<p>© 2025 My Blog</p>
</footer>
3.HTML Box Model:
Every HTML element on a webpage is treated like a box.
This box is made up of four layers, from inside to outside:
Content– text or image inside the element
Padding– space around the content
Border – a line around the padding
Margin – space outside the border (distance from other elements)
Box Model Structure:
┌───────────────────────────────┐
│ Margin │
│ ┌─────────────────────────┐ │
│ │ Border │ │
│ │ ┌───────────────────┐ │ │
│ │ │ Padding │ │ │
│ │ │ ┌─────────────┐ │ │ │
│ │ │ │ Content │ │ │ │
│ │ │ └─────────────┘ │ │ │
│ │ └───────────────────┘ │ │
│ └─────────────────────────┘ │
└───────────────────────────────┘
Example in Css:
.box {
width: 200px;
padding: 10px;
border: 2px solid black;
margin: 20px;
}
4.Purpose of the <meta> Tag:
The <meta> tag gives important information about the webpage to the browser and search engines. It doesn’t appear on the page but controls how the page is understood and displayed.
Main Uses
- Character encoding
<meta charset="UTF-8">
- Responsive design (mobile view):
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- SEO description:
<meta name="description" content="My website description">
- Keywords (rarely used now):
<meta name="keywords" content="html, css, web">
- Auto refresh/redirect:
<meta http-equiv="refresh" content="5">
5.self-closing tags:
Self-closing tags are HTML tags that do not need a separate closing tag.
They represent elements that don’t wrap any content.
Common Examples:
<br>— line break<hr>— horizontal line<img>— image tag<input>— form input field<meta>— metadata inside<link>— link to external files like CSS<source>— used in audio/video<area>— image map area
Top comments (1)
A few additional points:
idattribute is not guaranteed to be unique. i.e. duplicate ids can be specified without error or conflict.classattribute can have a value containing any number of class names, including none, space separated.styleattribute have a higher specificity than those specified for a class, element or id and can only be overridden using the!importantkeyword.Mozilla Developer Network (MDN) is your friend.